Cabana 0.8.0-dev
 
Loading...
Searching...
No Matches
Cabana_MemberTypes.hpp
Go to the documentation of this file.
1/****************************************************************************
2 * Copyright (c) 2018-2023 by the Cabana authors *
3 * All rights reserved. *
4 * *
5 * This file is part of the Cabana library. Cabana is distributed under a *
6 * BSD 3-clause license. For the licensing terms see the LICENSE file in *
7 * the top-level directory. *
8 * *
9 * SPDX-License-Identifier: BSD-3-Clause *
10 ****************************************************************************/
11
16#ifndef CABANA_MEMBERTYPES_HPP
17#define CABANA_MEMBERTYPES_HPP
18
19#include <cstdlib>
20#include <type_traits>
21
22namespace Cabana
23{
24//---------------------------------------------------------------------------//
26template <typename... Types>
28{
30 static constexpr std::size_t size = sizeof...( Types );
31};
32
33//---------------------------------------------------------------------------//
35template <class>
36struct is_member_types_impl : public std::false_type
37{
38};
39
40template <typename... Types>
41struct is_member_types_impl<MemberTypes<Types...>> : public std::true_type
42{
43};
45
47template <class T>
49 : public is_member_types_impl<typename std::remove_cv<T>::type>::type
50{
51};
52
53//---------------------------------------------------------------------------//
54// Get the type of the member at a given index.
55//---------------------------------------------------------------------------//
57template <std::size_t M, typename T, typename... Types>
58struct MemberTypeAtIndexImpl;
59
60template <typename T, typename... Types>
61struct MemberTypeAtIndexImpl<0, T, Types...>
62{
63 using type = T;
64};
65
66template <std::size_t M, typename T, typename... Types>
67struct MemberTypeAtIndexImpl
68{
69 using type = typename MemberTypeAtIndexImpl<M - 1, Types...>::type;
70};
72
74template <std::size_t M, typename... Types>
76
78template <std::size_t M, typename... Types>
79struct MemberTypeAtIndex<M, MemberTypes<Types...>>
80{
82 using type = typename MemberTypeAtIndexImpl<M, Types...>::type;
83};
84
85//---------------------------------------------------------------------------//
86// Check that member types are valid.
87//---------------------------------------------------------------------------//
89template <std::size_t M, typename T, typename... Types>
90struct CheckMemberTypesImpl;
91
92template <typename T, typename... Types>
93struct CheckMemberTypesImpl<0, T, Types...>
94{
95 using type = T;
96 static_assert( std::is_trivial<type>::value,
97 "Member types must be trivial" );
98
99 using value_type = typename std::remove_all_extents<type>::type;
100 static_assert( std::is_arithmetic<value_type>::value,
101 "Member value types must be arithmetic" );
102
103 // Return true so we get the whole stack to evaluate all the assertions.
104 static constexpr bool value = true;
105};
106
107template <std::size_t M, typename T, typename... Types>
108struct CheckMemberTypesImpl
109{
110 using type = T;
111 static_assert( std::is_trivial<type>::value,
112 "Member types must be trivial" );
113
114 using value_type = typename std::remove_all_extents<type>::type;
115 static_assert( std::is_arithmetic<value_type>::value,
116 "Member value types must be arithmetic" );
117
118 static constexpr bool value = CheckMemberTypesImpl<M - 1, Types...>::value;
119};
121
123template <typename... Types>
125
127template <typename... Types>
129{
131 static constexpr int size = MemberTypes<Types...>::size;
133 static constexpr bool value =
134 CheckMemberTypesImpl<size - 1, Types...>::value;
135};
136
137//---------------------------------------------------------------------------//
138
139} // end namespace Cabana
140
141#endif // end CABANA_MEMBERTYPES_HPP
Core: particle data structures and algorithms.
Definition Cabana_AoSoA.hpp:36
static constexpr bool value
Valid member type.
Definition Cabana_MemberTypes.hpp:133
static constexpr int size
Type size.
Definition Cabana_MemberTypes.hpp:131
Check that member types are valid.
Definition Cabana_MemberTypes.hpp:124
typename MemberTypeAtIndexImpl< M, Types... >::type type
Member type.
Definition Cabana_MemberTypes.hpp:82
Get the type of the member at a given index.
Definition Cabana_MemberTypes.hpp:75
General sequence of types for SoA and AoSoA member data.
Definition Cabana_MemberTypes.hpp:28
static constexpr std::size_t size
Definition Cabana_MemberTypes.hpp:30
Static type checker.
Definition Cabana_MemberTypes.hpp:50