| 1 |
//@HEADER |
| 2 |
// ************************************************************************ |
| 3 |
// |
| 4 |
// Kokkos v. 4.0 |
| 5 |
// Copyright (2022) National Technology & Engineering |
| 6 |
// Solutions of Sandia, LLC (NTESS). |
| 7 |
// |
| 8 |
// Under the terms of Contract DE-NA0003525 with NTESS, |
| 9 |
// the U.S. Government retains certain rights in this software. |
| 10 |
// |
| 11 |
// Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions. |
| 12 |
// See https://kokkos.org/LICENSE for license information. |
| 13 |
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 14 |
// |
| 15 |
//@HEADER |
| 16 |
#ifndef MDSPAN_INCLUDE_EXPERIMENTAL_BITS_TRAIT_BACKPORTS_HPP_ |
| 17 |
#define MDSPAN_INCLUDE_EXPERIMENTAL_BITS_TRAIT_BACKPORTS_HPP_ |
| 18 |
|
| 19 |
#include "macros.hpp" |
| 20 |
#include "config.hpp" |
| 21 |
|
| 22 |
#include <type_traits> |
| 23 |
#include <utility> // integer_sequence |
| 24 |
|
| 25 |
//============================================================================== |
| 26 |
// <editor-fold desc="Variable template trait backports (e.g., is_void_v)"> {{{1 |
| 27 |
|
| 28 |
#ifdef _MDSPAN_NEEDS_TRAIT_VARIABLE_TEMPLATE_BACKPORTS |
| 29 |
|
| 30 |
#if _MDSPAN_USE_VARIABLE_TEMPLATES |
| 31 |
namespace MDSPAN_IMPL_STANDARD_NAMESPACE { |
| 32 |
|
| 33 |
#define _MDSPAN_BACKPORT_TRAIT(TRAIT) \ |
| 34 |
template <class... Args> _MDSPAN_INLINE_VARIABLE constexpr auto TRAIT##_v = TRAIT<Args...>::value; |
| 35 |
|
| 36 |
_MDSPAN_BACKPORT_TRAIT(is_assignable) |
| 37 |
_MDSPAN_BACKPORT_TRAIT(is_constructible) |
| 38 |
_MDSPAN_BACKPORT_TRAIT(is_convertible) |
| 39 |
_MDSPAN_BACKPORT_TRAIT(is_default_constructible) |
| 40 |
_MDSPAN_BACKPORT_TRAIT(is_trivially_destructible) |
| 41 |
_MDSPAN_BACKPORT_TRAIT(is_same) |
| 42 |
_MDSPAN_BACKPORT_TRAIT(is_empty) |
| 43 |
_MDSPAN_BACKPORT_TRAIT(is_void) |
| 44 |
|
| 45 |
#undef _MDSPAN_BACKPORT_TRAIT |
| 46 |
|
| 47 |
} // end namespace MDSPAN_IMPL_STANDARD_NAMESPACE |
| 48 |
|
| 49 |
#endif // _MDSPAN_USE_VARIABLE_TEMPLATES |
| 50 |
|
| 51 |
#endif // _MDSPAN_NEEDS_TRAIT_VARIABLE_TEMPLATE_BACKPORTS |
| 52 |
|
| 53 |
// </editor-fold> end Variable template trait backports (e.g., is_void_v) }}}1 |
| 54 |
//============================================================================== |
| 55 |
|
| 56 |
//============================================================================== |
| 57 |
// <editor-fold desc="integer sequence (ugh...)"> {{{1 |
| 58 |
|
| 59 |
#if !defined(_MDSPAN_USE_INTEGER_SEQUENCE) || !_MDSPAN_USE_INTEGER_SEQUENCE |
| 60 |
|
| 61 |
namespace MDSPAN_IMPL_STANDARD_NAMESPACE { |
| 62 |
|
| 63 |
template <class T, T... Vals> |
| 64 |
struct integer_sequence { |
| 65 |
static constexpr size_t size() noexcept { return sizeof...(Vals); } |
| 66 |
using value_type = T; |
| 67 |
}; |
| 68 |
|
| 69 |
template <size_t... Vals> |
| 70 |
using index_sequence = std::integer_sequence<size_t, Vals...>; |
| 71 |
|
| 72 |
namespace __detail { |
| 73 |
|
| 74 |
template <class T, T N, T I, class Result> |
| 75 |
struct __make_int_seq_impl; |
| 76 |
|
| 77 |
template <class T, T N, T... Vals> |
| 78 |
struct __make_int_seq_impl<T, N, N, integer_sequence<T, Vals...>> |
| 79 |
{ |
| 80 |
using type = integer_sequence<T, Vals...>; |
| 81 |
}; |
| 82 |
|
| 83 |
template <class T, T N, T I, T... Vals> |
| 84 |
struct __make_int_seq_impl< |
| 85 |
T, N, I, integer_sequence<T, Vals...> |
| 86 |
> : __make_int_seq_impl<T, N, I+1, integer_sequence<T, Vals..., I>> |
| 87 |
{ }; |
| 88 |
|
| 89 |
} // end namespace __detail |
| 90 |
|
| 91 |
template <class T, T N> |
| 92 |
using make_integer_sequence = typename __detail::__make_int_seq_impl<T, N, 0, integer_sequence<T>>::type; |
| 93 |
|
| 94 |
template <size_t N> |
| 95 |
using make_index_sequence = typename __detail::__make_int_seq_impl<size_t, N, 0, integer_sequence<size_t>>::type; |
| 96 |
|
| 97 |
template <class... T> |
| 98 |
using index_sequence_for = make_index_sequence<sizeof...(T)>; |
| 99 |
|
| 100 |
} // end namespace MDSPAN_IMPL_STANDARD_NAMESPACE |
| 101 |
|
| 102 |
#endif |
| 103 |
|
| 104 |
// </editor-fold> end integer sequence (ugh...) }}}1 |
| 105 |
//============================================================================== |
| 106 |
|
| 107 |
//============================================================================== |
| 108 |
// <editor-fold desc="standard trait aliases"> {{{1 |
| 109 |
|
| 110 |
#if !defined(_MDSPAN_USE_STANDARD_TRAIT_ALIASES) || !_MDSPAN_USE_STANDARD_TRAIT_ALIASES |
| 111 |
|
| 112 |
namespace MDSPAN_IMPL_STANDARD_NAMESPACE { |
| 113 |
|
| 114 |
#define _MDSPAN_BACKPORT_TRAIT_ALIAS(TRAIT) \ |
| 115 |
template <class... Args> using TRAIT##_t = typename TRAIT<Args...>::type; |
| 116 |
|
| 117 |
_MDSPAN_BACKPORT_TRAIT_ALIAS(remove_cv) |
| 118 |
_MDSPAN_BACKPORT_TRAIT_ALIAS(remove_reference) |
| 119 |
|
| 120 |
template <bool _B, class _T=void> |
| 121 |
using enable_if_t = typename enable_if<_B, _T>::type; |
| 122 |
|
| 123 |
#undef _MDSPAN_BACKPORT_TRAIT_ALIAS |
| 124 |
|
| 125 |
} // end namespace MDSPAN_IMPL_STANDARD_NAMESPACE |
| 126 |
|
| 127 |
#endif |
| 128 |
|
| 129 |
// </editor-fold> end standard trait aliases }}}1 |
| 130 |
//============================================================================== |
| 131 |
|
| 132 |
#endif //MDSPAN_INCLUDE_EXPERIMENTAL_BITS_TRAIT_BACKPORTS_HPP_ |