HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
meta.h
Go to the documentation of this file.
1 //
2 // Copyright 2023 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 
8 #ifndef PXR_BASE_TF_META_H
9 #define PXR_BASE_TF_META_H
10 
11 #include "pxr/pxr.h"
12 
13 #include <cstddef>
14 #include <tuple>
15 #include <type_traits>
16 
17 // Some small metaprogramming utilities.
18 
20 
21 // Simple compile-time type list.
22 template <class... Args> struct TfMetaList {};
23 
24 // Helper for TfMetaApply.
25 template<template <class...> class Cls, class List>
27 
28 template<template <class...> class Cls, class... Args>
29 struct Tf_MetaApplyImpl<Cls, TfMetaList<Args...>>
30 {
31  using Type = Cls<Args...>;
32 };
33 
34 // Apply \p TypeList<Args...> to class template \p Cls, producing Cls<Args...>
35 template <template <class...> class Cls, class TypeList>
37 
38 // TfMetaHead<A1, A2, ... An> -> A1
39 template <class Head, class...>
40 using TfMetaHead = Head;
41 
42 // TfMetaTail<A1, A2, ... An> -> TfMetaList<A2, ... An>.
43 template <class Head, class... Tail>
44 using TfMetaTail = TfMetaList<Tail...>;
45 
46 // TfMetaDecay<A1, A2, ... An> ->
47 // TfMetaList<std::decay_t<A1>, ... std::decay_t<An>>
48 template <class... Ts>
50 
51 // TfMetaLength produces an integral_constant<size_t, N> where N is the number
52 // of \p Xs.
53 template <class... Xs>
54 using TfMetaLength = std::integral_constant<size_t, sizeof...(Xs)>;
55 
56 // Lighter-weight compile-time conditional type selection implementation.
57 template <bool Condition>
59  template <class T, class>
60  using Type = T;
61 };
62 
63 template <>
64 struct Tf_ConditionalImpl<false> {
65  template <class, class F>
66  using Type = F;
67 };
68 
69 // This is a bit lighter weight at compile time than std::conditional because it
70 // instantiates a separate template for the condition from the selector.
71 template <bool Cond, class T, class F>
72 using TfConditionalType =
74 
76 
77 #endif // PXR_BASE_TF_META_H
std::integral_constant< size_t, sizeof...(Xs)> TfMetaLength
Definition: meta.h:54
typename Tf_ConditionalImpl< Cond >::template Type< T, F > TfConditionalType
Definition: meta.h:73
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
Head TfMetaHead
Definition: meta.h:40
typename Tf_MetaApplyImpl< Cls, TypeList >::Type TfMetaApply
Definition: meta.h:36