-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add has_constant_size<T>; use it in hash_append
- Loading branch information
Showing
6 changed files
with
161 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#ifndef BOOST_HASH2_HAS_CONSTANT_SIZE_HPP_INCLUDED | ||
#define BOOST_HASH2_HAS_CONSTANT_SIZE_HPP_INCLUDED | ||
|
||
// Copyright 2024 Peter Dimov | ||
// Distributed under the Boost Software License, Version 1.0. | ||
// https://www.boost.org/LICENSE_1_0.txt | ||
|
||
#include <type_traits> | ||
#include <utility> | ||
|
||
namespace boost | ||
{ | ||
|
||
// forward declaration | ||
template<class T, std::size_t N> class array; | ||
|
||
namespace hash2 | ||
{ | ||
|
||
// forward declaration | ||
template<std::size_t N> class digest; | ||
|
||
// detail::has_tuple_size | ||
|
||
namespace detail | ||
{ | ||
|
||
template<class T, class En = void> struct has_tuple_size: std::false_type | ||
{ | ||
}; | ||
|
||
template<class T> struct has_tuple_size<T, | ||
typename std::enable_if< | ||
std::tuple_size<T>::value == std::tuple_size<T>::value | ||
>::type | ||
>: std::true_type | ||
{ | ||
}; | ||
|
||
} // namespace detail | ||
|
||
// has_constant_size | ||
|
||
template<class T> struct has_constant_size: detail::has_tuple_size<T> | ||
{ | ||
}; | ||
|
||
template<class T, std::size_t N> struct has_constant_size< boost::array<T, N> >: std::true_type | ||
{ | ||
}; | ||
|
||
template<std::size_t N> struct has_constant_size< digest<N> >: std::true_type | ||
{ | ||
}; | ||
|
||
template<class T> struct has_constant_size<T const>: has_constant_size<T> | ||
{ | ||
}; | ||
|
||
} // namespace hash2 | ||
} // namespace boost | ||
|
||
#endif // #ifndef BOOST_HASH2_HAS_CONSTANT_SIZE_HPP_INCLUDED |
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,66 @@ | ||
// Copyright 2017, 2023, 2024 Peter Dimov | ||
// Distributed under the Boost Software License, Version 1.0. | ||
// https://www.boost.org/LICENSE_1_0.txt | ||
|
||
#include <boost/hash2/has_constant_size.hpp> | ||
#include <boost/hash2/digest.hpp> | ||
#include <boost/core/lightweight_test_trait.hpp> | ||
#include <boost/array.hpp> | ||
#include <array> | ||
#include <string> | ||
#include <vector> | ||
#include <set> | ||
|
||
template<class T> void test( bool exp ) | ||
{ | ||
using boost::hash2::has_constant_size; | ||
|
||
if( exp ) | ||
{ | ||
BOOST_TEST_TRAIT_TRUE((has_constant_size<T>)); | ||
BOOST_TEST_TRAIT_TRUE((has_constant_size<T const>)); | ||
} | ||
else | ||
{ | ||
BOOST_TEST_TRAIT_FALSE((has_constant_size<T>)); | ||
BOOST_TEST_TRAIT_FALSE((has_constant_size<T const>)); | ||
} | ||
} | ||
|
||
struct X | ||
{ | ||
}; | ||
|
||
int main() | ||
{ | ||
test< void >( false ); | ||
test< X >( false ); | ||
|
||
test< std::vector<int> >( false ); | ||
test< std::vector<X> >( false ); | ||
test< std::string >( false ); | ||
test< std::set<int> >( false ); | ||
|
||
test< std::array<int, 3> >( true ); | ||
test< std::array<int, 0> >( true ); | ||
|
||
test< std::array<X, 3> >( true ); | ||
test< std::array<X, 0> >( true ); | ||
|
||
test< boost::array<int, 5> >( true ); | ||
test< boost::array<int, 0> >( true ); | ||
|
||
test< boost::array<X, 7> >( true ); | ||
test< boost::array<X, 0> >( true ); | ||
|
||
test< std::array<int, 9> >( true ); | ||
test< std::array<int, 0> >( true ); | ||
|
||
using boost::hash2::digest; | ||
|
||
test< digest<1> >( true ); | ||
test< digest<16> >( true ); | ||
test< digest<20> >( true ); | ||
|
||
return boost::report_errors(); | ||
} |