traits: add is_contiguous query for containers

This commit is contained in:
Danny Robson 2017-12-28 17:48:21 +11:00
parent d8f3469987
commit 27a93c0780
2 changed files with 28 additions and 0 deletions

View File

@ -1,6 +1,8 @@
#include <cruft/util/tap.hpp>
#include <cruft/util/types/traits.hpp>
#include <list>
///////////////////////////////////////////////////////////////////////////////
template <typename FuncT>
@ -56,4 +58,10 @@ main (void)
"complex function type");
tap.expect (!has_return_type<int>::value, "integer is not applicable to func_traits");
tap.expect (is_contiguous_v<std::vector<char>>, "vector is contiguous");
tap.expect (is_contiguous_v<std::array<char,4>>, "array is contiguous");
tap.expect (!is_contiguous_v<std::list<char>>, "list is not contiguous");
return tap.status ();
}

View File

@ -270,4 +270,24 @@ template <std::size_t N, typename FuncT>
using nth_argument_t = typename nth_argument<N, FuncT>::type;
///////////////////////////////////////////////////////////////////////////////
#include <string>
#include <array>
#include <vector>
template <typename T>
struct is_contiguous : public std::false_type {};
template <typename CharT, typename Traits, typename Allocator>
struct is_contiguous<std::basic_string<CharT, Traits, Allocator>> : public std::true_type {};
template <typename T, std::size_t N>
struct is_contiguous<std::array<T,N>>: public std::true_type {};
template <typename T, typename Allocator>
struct is_contiguous<std::vector<T,Allocator>>: public std::true_type {};
template <typename T>
constexpr auto is_contiguous_v = is_contiguous<T>::value;
#endif