Vc 1.4.5
SIMD Vector Classes for C++
 
Loading...
Searching...
No Matches
has_contiguous_storage.h
1/* This file is part of the Vc library. {{{
2Copyright © 2014-2016 Matthias Kretz <kretz@kde.org>
3
4Redistribution and use in source and binary forms, with or without
5modification, 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
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
19DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22ON 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
24SOFTWARE, 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
37namespace std
38{
39#endif
40#ifdef _WIN32
41template <typename T, size_t N> class array;
42#else
43template <typename T, size_t N> struct array;
44#endif
45template <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
52namespace Vc_VERSIONED_NAMESPACE
53{
54namespace Traits
55{
56namespace has_contiguous_storage_detail
57{
58// heuristic: consider RandomAccessIterator as abstracting contiguous storage
59// case 1: T is a container
60template <typename T, typename It = typename T::iterator>
61std::is_base_of<std::random_access_iterator_tag,
62 typename std::iterator_traits<It>::iterator_category>
63test(int);
64
65// case 2: T is an iterator type
66template <typename T>
67std::is_base_of<std::random_access_iterator_tag,
68 typename std::iterator_traits<T>::iterator_category>
69test(long);
70
71// case 3: everything else
72template <typename T> std::false_type test(...);
73} // namespace has_contiguous_storage_detail
74
75template <typename T>
76struct has_contiguous_storage_impl
77 : public decltype(has_contiguous_storage_detail::test<T>(int())) {
78};
79
80template <typename T>
81struct has_contiguous_storage
82 : public has_contiguous_storage_impl<
83 typename std::remove_cv<typename std::remove_reference<T>::type>::type>
84{
85};
86
87// spezializations:
88template <typename T> struct has_contiguous_storage_impl<const T *> : public std::true_type {};
89template <typename T> struct has_contiguous_storage_impl<T *> : public std::true_type {};
90template <typename T> struct has_contiguous_storage_impl<std::unique_ptr<T[]>> : public std::true_type {};
91template <typename T> struct has_contiguous_storage_impl<std::initializer_list<T>> : public std::true_type {};
92template <typename T, std::size_t N> struct has_contiguous_storage_impl<T[N]> : public std::true_type {};
93template <typename T, std::size_t N> struct has_contiguous_storage_impl<std::array<T, N>> : public std::true_type {};
94template <typename T, typename A> struct has_contiguous_storage_impl<std::vector<T, A>> : public std::true_type {};
95
96} // namespace Traits
97} // namespace Vc
98
99#endif // VC_TRAITS_HAS_CONTIGUOUS_STORAGE_H_
Common::AdaptSubscriptOperator< std::vector< T, Allocator > > vector
An adapted std::vector container with an additional subscript operator which implements gather and sc...
Definition vector:55