Last active
November 26, 2015 02:27
-
-
Save ricejasonf/2f2e03b31fe9dfb09333 to your computer and use it in GitHub Desktop.
Benchmark checking for duplicate types.
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
#include<boost/hana.hpp> | |
namespace hana = boost::hana; | |
auto list_with_no_dups = | |
hana::unpack( | |
hana::range_c<int, 0, 50>, | |
[](auto... i) { | |
return hana::tuple_c<int, i...>; | |
}); | |
auto list_with_dups = | |
hana::unpack( | |
hana::range_c<int, 0, 50>, | |
[](auto... i) { | |
return hana::tuple_c<int, (i % 10)...>; | |
}); | |
template <typename Foldable> | |
/*constexpr*/ auto has_duplicates(Foldable const& foldable) { | |
return hana::unpack(foldable, | |
[&](auto const& ...x) { | |
constexpr std::size_t counts[] = { | |
decltype(hana::count(foldable, x))::value... | |
}; | |
return hana::bool_c< | |
hana::detail::find_if(counts, counts + sizeof...(x), hana::_ > 1u) | |
!= | |
counts + sizeof...(x) | |
>; | |
}); | |
} | |
int main() { | |
BOOST_HANA_CONSTANT_CHECK(!has_duplicates(list_with_no_dups)); | |
BOOST_HANA_CONSTANT_CHECK(has_duplicates(list_with_dups)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment