Tensor Comprehensions
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
vararg.h
Go to the documentation of this file.
1 
16 #pragma once
17 
18 #include <type_traits>
19 #include <vector>
20 
21 namespace tc {
22 namespace {
23 
27 template <typename T>
28 void inplaceVectorFromArgs(std::vector<T>&) {
29  // recursion stopper
30 }
31 
32 template <typename T, typename Arg, typename... Args>
33 void inplaceVectorFromArgs(std::vector<T>& v, Arg arg, Args... args) {
34  static_assert(
35  std::is_same<T, typename std::remove_reference<Arg>::type>::value,
36  "expected identical types");
37  v.push_back(std::forward<Arg>(arg));
38  inplaceVectorFromArgs(v, std::forward<Args>(args)...);
39 }
40 } // namespace
41 
44 template <typename Arg>
45 std::vector<Arg> vectorFromArgs() {
46  std::vector<Arg> v;
47  return v;
48 }
49 
51 template <typename Arg, typename... Args>
52 std::vector<typename std::remove_reference<Arg>::type> vectorFromArgs(
53  Arg arg,
54  Args... args) {
55  std::vector<typename std::remove_reference<Arg>::type> v;
56  inplaceVectorFromArgs(v, std::forward<Arg>(arg), std::forward<Args>(args)...);
57  return v;
58 }
59 
60 template <typename Arg, typename... Args>
61 std::vector<typename std::remove_reference<Arg>::type> vectorFromCastedArgs(
62  Args... args) {
63  std::vector<typename std::remove_reference<Arg>::type> v;
64  inplaceVectorFromArgs(v, static_cast<Arg>(args)...);
65  return v;
66 }
67 
68 template <template <class> class ConditionType, typename T, typename... Args>
69 struct TemplArgsAll {
70  const static bool value =
71  ConditionType<T>::value && TemplArgsAll<ConditionType, Args...>::value;
72 };
73 
74 template <template <class> class ConditionType, typename T>
75 struct TemplArgsAll<ConditionType, T> {
76  const static bool value = ConditionType<T>::value;
77 };
78 
79 template <template <class> class ConditionType>
80 struct TemplArgsAll<ConditionType, void> {
81  const static bool value = true;
82 };
83 
84 } // namespace tc
std::vector< typename std::remove_reference< Arg >::type > vectorFromCastedArgs(Args...args)
Definition: vararg.h:61
std::vector< Arg > vectorFromArgs()
Definition: vararg.h:45
static const bool value
Definition: vararg.h:70
Definition: vararg.h:69