Vc  1.3.2-dev
SIMD Vector Classes for C++
has_contiguous_storage.h
1 /* This file is part of the Vc library. {{{
2 Copyright © 2014-2016 Matthias Kretz <kretz@kde.org>
3 
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions are met:
6  * Redistributions of source code must retain the above copyright
7  notice, this list of conditions and the following disclaimer.
8  * Redistributions in binary form must reproduce the above copyright
9  notice, this list of conditions and the following disclaimer in the
10  documentation and/or other materials provided with the distribution.
11  * Neither the names of contributing organizations nor the
12  names of its contributors may be used to endorse or promote products
13  derived from this software without specific prior written permission.
14 
15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
19 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 
26 }}}*/
27 
28 #ifndef VC_TRAITS_HAS_CONTIGUOUS_STORAGE_H_
29 #define VC_TRAITS_HAS_CONTIGUOUS_STORAGE_H_
30 
31 #include <initializer_list>
32 #include <memory>
33 
34 #ifdef _LIBCPP_BEGIN_NAMESPACE_STD
35 _LIBCPP_BEGIN_NAMESPACE_STD
36 #else
37 namespace std
38 {
39 #endif
40 #ifdef _WIN32
41 template <typename T, size_t N> class array;
42 #else
43 template <typename T, size_t N> struct array;
44 #endif
45 template <typename T, typename Allocator> class vector;
46 #ifdef _LIBCPP_END_NAMESPACE_STD
47 _LIBCPP_END_NAMESPACE_STD
48 #else
49 } // namespace std
50 #endif
51 
52 namespace Vc_VERSIONED_NAMESPACE
53 {
54 namespace Traits
55 {
56 namespace has_contiguous_storage_detail
57 {
58 template <typename T, typename It = typename T::iterator>
59 std::is_base_of<std::random_access_iterator_tag,
60  typename It::iterator_category>
61 test(int); // this is only a heuristic. Having a RandomAccessIterator does not guarantee
62  // contiguous storage
63 template <typename T>
64 std::is_base_of<std::random_access_iterator_tag,
65  typename T::iterator_category>
66 test(long); // this is only a heuristic. Having a RandomAccessIterator does not guarantee
67  // contiguous storage
68 template <typename T> std::false_type test(...);
69 } // namespace has_contiguous_storage_detail
70 
71 template <typename T>
72 struct has_contiguous_storage_impl
73  : public decltype(has_contiguous_storage_detail::test<T>(int())) {
74 };
75 
76 template <typename T>
77 struct has_contiguous_storage
78  : public has_contiguous_storage_impl<
79  typename std::remove_cv<typename std::remove_reference<T>::type>::type>
80 {
81 };
82 
83 // spezializations:
84 template <typename T> struct has_contiguous_storage_impl<const T *> : public std::true_type {};
85 template <typename T> struct has_contiguous_storage_impl<T *> : public std::true_type {};
86 template <typename T> struct has_contiguous_storage_impl<std::unique_ptr<T[]>> : public std::true_type {};
87 template <typename T> struct has_contiguous_storage_impl<std::initializer_list<T>> : public std::true_type {};
88 template <typename T, std::size_t N> struct has_contiguous_storage_impl<T[N]> : public std::true_type {};
89 template <typename T, std::size_t N> struct has_contiguous_storage_impl<std::array<T, N>> : public std::true_type {};
90 template <typename T, typename A> struct has_contiguous_storage_impl<std::vector<T, A>> : public std::true_type {};
91 
92 } // namespace Traits
93 } // namespace Vc
94 
95 #endif // VC_TRAITS_HAS_CONTIGUOUS_STORAGE_H_
Definition: vector.h:257
Common::AdaptSubscriptOperator< std::vector< T, Allocator >> vector
An adapted std::vector container with an additional subscript operator which implements gather and sc...
Definition: vector:51