Advanced Multi-Physics (AMP)
On-Line Documentation
to_tuple.h
Go to the documentation of this file.
1// This file contains helper functions to convert a simple struct to a tuple
2#ifndef included_AMP_to_tuple
3#define included_AMP_to_tuple
4
5#include "AMP/utils/MacroFunctions.h"
6
7
8#include <tuple>
9#include <type_traits>
10
11
12namespace AMP {
13
14
15// Helper functions
16struct any_type {
17 template<class T>
18 constexpr operator T();
19};
20template<class T, typename... Args>
21decltype( void( T{ std::declval<Args>()... } ), std::true_type() ) test( int );
22template<class T, typename... Args>
23std::false_type test( ... );
24template<class T, typename... Args>
25struct is_braces_constructible : decltype( test<T, Args...>( 0 ) ) {
26};
27template<class T, typename... Args>
28inline constexpr bool is_braces_constructible_v = is_braces_constructible<T, Args...>{};
29
30
31// Helper macros
32#define AMP_PRINT( X ) _##X
33#define AMP_COMMA() ,
34#define AMP_ANY( X ) any_type
35#define AMP_TO_TUPLE_BLOCK2( N ) \
36 if constexpr ( is_braces_constructible_v<type, AMP_SEQ_U( N, AMP_ANY, AMP_COMMA )> ) { \
37 auto &&[AMP_SEQ_U( N, AMP_PRINT, AMP_COMMA )] = object; \
38 return std::make_tuple( AMP_SEQ_U( N, AMP_PRINT, AMP_COMMA ) ); \
39 } else
40#define AMP_TO_TUPLE_BLOCK( N ) AMP_SEQ_D( N, AMP_TO_TUPLE_BLOCK2, AMP_NULL )
41
42
43// Convert an object (struct) to a tuple
44// Note to view the code below run:
45// g++ -E to_tuple.h -I /projects/AMP/build/debug/AMP/include | clang-format | tail -n 50
46template<class T>
47auto to_tuple( T &&object ) noexcept
48{
49#ifndef DISABLE_TO_TUPLE
50 using type = std::decay_t<T>;
51 AMP_TO_TUPLE_BLOCK( 64 ) { return std::make_tuple(); }
52#else
53 AMP_ERROR( "to_tuple is not supported by compiler" )
54#endif
55}
56
57
58} // namespace AMP
59
60
61#endif
#define AMP_ERROR(MSG)
Throw error.
constexpr bool is_braces_constructible_v
Definition to_tuple.h:28
decltype(void(T{ std::declval< Args >()... }), std::true_type()) test(int)
auto to_tuple(T &&object) noexcept
Definition to_tuple.h:47
#define AMP_TO_TUPLE_BLOCK(N)
Definition to_tuple.h:40



Advanced Multi-Physics (AMP)
Oak Ridge National Laboratory
Idaho National Laboratory
Los Alamos National Laboratory
This page automatically produced from the
source code by doxygen
Last updated: Tue Mar 10 2026 13:06:41.
Comments on this page