From 27a93c078062af8c8fbcc5302432bb5385471c1c Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Thu, 28 Dec 2017 17:48:21 +1100 Subject: [PATCH] traits: add is_contiguous query for containers --- test/traits.cpp | 8 ++++++++ types/traits.hpp | 20 ++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/test/traits.cpp b/test/traits.cpp index 90d5e4bc..7f87b278 100644 --- a/test/traits.cpp +++ b/test/traits.cpp @@ -1,6 +1,8 @@ #include #include +#include + /////////////////////////////////////////////////////////////////////////////// template @@ -56,4 +58,10 @@ main (void) "complex function type"); tap.expect (!has_return_type::value, "integer is not applicable to func_traits"); + + + tap.expect (is_contiguous_v>, "vector is contiguous"); + tap.expect (is_contiguous_v>, "array is contiguous"); + tap.expect (!is_contiguous_v>, "list is not contiguous"); + return tap.status (); } \ No newline at end of file diff --git a/types/traits.hpp b/types/traits.hpp index fbde1c3d..14cfd55e 100644 --- a/types/traits.hpp +++ b/types/traits.hpp @@ -270,4 +270,24 @@ template using nth_argument_t = typename nth_argument::type; +/////////////////////////////////////////////////////////////////////////////// +#include +#include +#include + +template +struct is_contiguous : public std::false_type {}; + +template +struct is_contiguous> : public std::true_type {}; + +template +struct is_contiguous>: public std::true_type {}; + +template +struct is_contiguous>: public std::true_type {}; + +template +constexpr auto is_contiguous_v = is_contiguous::value; + #endif