Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add BOOST_HANA_ENABLE_DEBUG_MODE and optional checks in make_set and …
…make_map Closes #230
- Loading branch information
Showing
8 changed files
with
168 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/*! | ||
@file | ||
Defines `boost::hana::detail::has_duplicates`. | ||
@copyright Louis Dionne 2013-2016 | ||
Distributed under the Boost Software License, Version 1.0. | ||
(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) | ||
*/ | ||
|
||
#ifndef BOOST_HANA_DETAIL_HAS_DUPLICATES_HPP | ||
#define BOOST_HANA_DETAIL_HAS_DUPLICATES_HPP | ||
|
||
#include <boost/hana/config.hpp> | ||
#include <boost/hana/detail/fast_and.hpp> | ||
#include <boost/hana/equal.hpp> | ||
|
||
#include <cstddef> | ||
#include <utility> | ||
|
||
|
||
BOOST_HANA_NAMESPACE_BEGIN namespace detail { | ||
template <typename T, typename ...U> | ||
constexpr std::size_t pack_count() { | ||
std::size_t c = 0; | ||
std::size_t expand[] = {0, // avoid empty array | ||
(decltype(hana::equal(std::declval<T>(), std::declval<U>()))::value | ||
? ++c | ||
: c)... | ||
}; | ||
(void)expand; | ||
|
||
return c; | ||
} | ||
|
||
//! @ingroup group-details | ||
//! Returns whether any of the `T`s are duplicate w.r.t. `hana::equal`. | ||
//! | ||
//! In particular, this does not check whether all of the `T`s are unique | ||
//! as _types_, but rather whether they are unique when compared as | ||
//! `hana::equal(std::declval<T>(), std::declval<U>())`. This assumes | ||
//! the comparison to return an `IntegralConstant` that can be explicitly | ||
//! converted to `bool`. | ||
//! | ||
//! @note | ||
//! Since this utility is mostly used in assertions to check that there | ||
//! are no duplicates in a sequence, we expect it to return `false` most | ||
//! of the time (otherwise we will assert). Hence, this implementation is | ||
//! biased towards the fact that we __will__ have to compare every pair of | ||
//! elements in most cases, and it does not try to be lazy. | ||
//! | ||
//! @todo | ||
//! This implementation is O(n^2). We could do it in O(n), but that would | ||
//! require a more elaborate setup including storage with O(1) lookup | ||
//! (which could be based on a compile-time hash). If we implement such | ||
//! storage for associative sequences, we could use it to optimize this. | ||
template <typename ...T> | ||
struct has_duplicates { | ||
static constexpr bool value = | ||
sizeof...(T) > 0 && | ||
!detail::fast_and<(detail::pack_count<T, T...>() == 1)...>::value | ||
; | ||
}; | ||
} BOOST_HANA_NAMESPACE_END | ||
|
||
#endif // !BOOST_HANA_DETAIL_HAS_DUPLICATES_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
@copyright Louis Dionne 2013-2016 | ||
Distributed under the Boost Software License, Version 1.0. | ||
(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) | ||
*/ | ||
|
||
#include <boost/hana/detail/has_duplicates.hpp> | ||
#include <boost/hana/integral_constant.hpp> | ||
namespace hana = boost::hana; | ||
|
||
|
||
static_assert(!hana::detail::has_duplicates<>::value, ""); | ||
|
||
static_assert(!hana::detail::has_duplicates< | ||
hana::int_<0> | ||
>::value, ""); | ||
|
||
static_assert(!hana::detail::has_duplicates< | ||
hana::int_<0>, hana::int_<1> | ||
>::value, ""); | ||
|
||
static_assert(!hana::detail::has_duplicates< | ||
hana::int_<0>, hana::int_<1>, hana::int_<2> | ||
>::value, ""); | ||
|
||
static_assert(hana::detail::has_duplicates< | ||
hana::int_<0>, hana::int_<0>, hana::int_<2> | ||
>::value, ""); | ||
|
||
static_assert(hana::detail::has_duplicates< | ||
hana::int_<0>, hana::int_<1>, hana::int_<0> | ||
>::value, ""); | ||
|
||
static_assert(hana::detail::has_duplicates< | ||
hana::int_<0>, hana::int_<1>, hana::int_<2>, hana::int_<1> | ||
>::value, ""); | ||
|
||
static_assert(hana::detail::has_duplicates< | ||
hana::int_<0>, hana::int_<1>, hana::int_<2>, hana::int_<2> | ||
>::value, ""); | ||
|
||
static_assert(hana::detail::has_duplicates< | ||
hana::int_<0>, hana::int_<1>, hana::int_<2>, hana::int_<1>, hana::int_<1> | ||
>::value, ""); | ||
|
||
static_assert(hana::detail::has_duplicates< | ||
hana::int_<0>, hana::int_<1>, hana::int_<2>, hana::int_<1>, hana::int_<2> | ||
>::value, ""); | ||
|
||
// Make sure it uses deep equality | ||
static_assert(hana::detail::has_duplicates< | ||
hana::int_<0>, hana::long_<0>, hana::int_<2>, hana::int_<3> | ||
>::value, ""); | ||
|
||
static_assert(hana::detail::has_duplicates< | ||
hana::int_<0>, hana::int_<1>, hana::int_<2>, hana::long_<1> | ||
>::value, ""); | ||
|
||
int main() { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters