Cabana 0.8.0-dev
 
Loading...
Searching...
No Matches
Cabana_Tuple.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_TUPLE_HPP
17#define CABANA_TUPLE_HPP
18
20#include <Cabana_SoA.hpp>
21
22#include <Kokkos_Core.hpp>
23
24#include <cstdlib>
25#include <type_traits>
26
27namespace Cabana
28{
29//---------------------------------------------------------------------------//
30// Forward declaration of tuple.
31template <typename DataTypes>
32struct Tuple;
33
34//---------------------------------------------------------------------------//
36template <class>
37struct is_tuple_impl : public std::false_type
38{
39};
40
41template <class DataTypes>
42struct is_tuple_impl<Tuple<DataTypes>> : public std::true_type
43{
44};
46
48template <class T>
49struct is_tuple : public is_tuple_impl<typename std::remove_cv<T>::type>::type
50{
51};
52
53//---------------------------------------------------------------------------//
54// Get template helper.
55
57template <std::size_t M, class Tuple_t>
58KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
60 typename Tuple_t::template member_reference_type<M>>::type
61get( Tuple_t& tp )
62{
63 return get<M>( static_cast<typename Tuple_t::base&>( tp ), 0 );
64}
65
67template <std::size_t M, class Tuple_t>
68KOKKOS_FORCEINLINE_FUNCTION
69 typename Tuple_t::template member_const_reference_type<M>
70 get( const Tuple_t& tp )
71{
72 return get<M>( static_cast<const typename Tuple_t::base&>( tp ), 0 );
73}
74
76template <std::size_t M, class Tuple_t>
77KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
78 is_tuple<Tuple_t>::value,
79 typename Tuple_t::template member_reference_type<M>>::type
80get( Tuple_t& tp, const std::size_t d0 )
81{
82 return get<M>( static_cast<typename Tuple_t::base&>( tp ), 0, d0 );
83}
84
86template <std::size_t M, class Tuple_t>
87KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
88 is_tuple<Tuple_t>::value,
89 typename Tuple_t::template member_const_reference_type<M>>::type
90get( const Tuple_t& tp, const std::size_t d0 )
91{
92 return get<M>( static_cast<const typename Tuple_t::base&>( tp ), 0, d0 );
93}
94
96template <std::size_t M, class Tuple_t>
97KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
98 is_tuple<Tuple_t>::value,
99 typename Tuple_t::template member_reference_type<M>>::type
100get( Tuple_t& tp, const std::size_t d0, const std::size_t d1 )
101{
102 return get<M>( static_cast<typename Tuple_t::base&>( tp ), 0, d0, d1 );
103}
104
106template <std::size_t M, class Tuple_t>
107KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
108 is_tuple<Tuple_t>::value,
109 typename Tuple_t::template member_const_reference_type<M>>::type
110get( const Tuple_t& tp, const std::size_t d0, const std::size_t d1 )
111{
112 return get<M>( static_cast<const typename Tuple_t::base&>( tp ), 0, d0,
113 d1 );
114}
115
117template <std::size_t M, class Tuple_t>
118KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
119 is_tuple<Tuple_t>::value,
120 typename Tuple_t::template member_reference_type<M>>::type
121get( Tuple_t& tp, const std::size_t d0, const std::size_t d1,
122 const std::size_t d2 )
123{
124 return get<M>( static_cast<typename Tuple_t::base&>( tp ), 0, d0, d1, d2 );
125}
126
128template <std::size_t M, class Tuple_t>
129KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
130 is_tuple<Tuple_t>::value,
131 typename Tuple_t::template member_const_reference_type<M>>::type
132get( const Tuple_t& tp, const std::size_t d0, const std::size_t d1,
133 const std::size_t d2 )
134{
135 return get<M>( static_cast<const typename Tuple_t::base&>( tp ), 0, d0, d1,
136 d2 );
137}
138
139//---------------------------------------------------------------------------//
149template <typename... Types>
150struct Tuple<MemberTypes<Types...>> : SoA<MemberTypes<Types...>, 1>
151{
153 using base = SoA<MemberTypes<Types...>, 1>;
154
155 KOKKOS_DEFAULTED_FUNCTION Tuple() = default;
156
158 KOKKOS_FORCEINLINE_FUNCTION Tuple( const Tuple& t )
159 {
160 Impl::tupleCopy( *this, 0, t, 0 );
161 }
162
164 KOKKOS_FORCEINLINE_FUNCTION Tuple( Tuple&& t )
165 {
166 Impl::tupleCopy( *this, 0, t, 0 );
167 }
168
170 KOKKOS_FORCEINLINE_FUNCTION Tuple& operator=( const Tuple& t )
171 {
172 Impl::tupleCopy( *this, 0, t, 0 );
173 return *this;
174 }
175
177 KOKKOS_FORCEINLINE_FUNCTION Tuple& operator=( Tuple&& t )
178 {
179 Impl::tupleCopy( *this, 0, t, 0 );
180 return *this;
181 }
182};
183
184//---------------------------------------------------------------------------//
185
186} // end namespace Cabana
187
188#endif // end CABANA_TUPLE_HPP
AoSoA tuple member types.
Struct-of-Arrays for building AoSoA.
Core: particle data structures and algorithms.
Definition Cabana_AoSoA.hpp:36
KOKKOS_FORCEINLINE_FUNCTION std::enable_if< is_parameter_pack< ParameterPack_t >::value, typenameParameterPack_t::templatevalue_type< N > & >::type get(ParameterPack_t &pp)
Get an element from a parameter pack.
Definition Cabana_ParameterPack.hpp:129
General sequence of types for SoA and AoSoA member data.
Definition Cabana_MemberTypes.hpp:28
Definition Cabana_SoA.hpp:32
KOKKOS_FORCEINLINE_FUNCTION Tuple(Tuple &&t)
Copy constructor.
Definition Cabana_Tuple.hpp:164
SoA< MemberTypes< Types... >, 1 > base
Base type.
Definition Cabana_Tuple.hpp:153
KOKKOS_FORCEINLINE_FUNCTION Tuple & operator=(Tuple &&t)
Assignment operator.
Definition Cabana_Tuple.hpp:177
KOKKOS_FORCEINLINE_FUNCTION Tuple(const Tuple &t)
Const copy constructor.
Definition Cabana_Tuple.hpp:158
KOKKOS_FORCEINLINE_FUNCTION Tuple & operator=(const Tuple &t)
Const assignment operator.
Definition Cabana_Tuple.hpp:170
Definition Cabana_Tuple.hpp:32
Tuple static type checker.
Definition Cabana_Tuple.hpp:50