variadic-templates

static const array of values in Variadic Template C++

若如初见. 提交于 2019-12-13 04:25:30
问题 I have a function that I want to be able to runtime check the argument types of as I'm casting a void pointer back to a function. Curious as to how I turn the list of arguments into into a hash using the TypeToEnum template that is constructed like #define DEFINE_TYPE(x)\ template<>\ struct TypeToEnum<x>\ {\ public:\ static const unsigned int value = HashString(#x);\ };\ That way I can determine the function signature using templates. I just have no idea how to convert that into a static

Flattening a pack of types, where non-type values are part of the flattening

╄→尐↘猪︶ㄣ 提交于 2019-12-13 02:59:47
问题 If you look at the member type of template <typename Pack> struct flatten; template <typename T, typename U, std::size_t A, std::size_t B, std::size_t C, typename V, std::size_t D, std::size_t E, typename W> struct flatten<std::tuple<T,U, std::index_sequence<A,B,C>, V, std::index_sequence<D,E>, W>> { template <typename, typename, std::size_t, std::size_t, std::size_t, typename, std::size_t, std::size_t, typename> struct S; using type = S<T,U,A,B,C,V,D,E,W>; }; is it possible to do this

Using n arguments from Args… starting from position m

为君一笑 提交于 2019-12-13 02:22:45
问题 Say I have different functions, which have a variable number of arguments. The first argument is always a pointer obtained through other means. All other arguments I obtain through another template using template pack expansion. Template that I use for calling these functions is as follows: template<typename RT, typename... Args> inline RT call(RT(*function)(Args...)) { return function(pointer_from_somewhere, bind_argument<Args>::get_arg()...); } This obviously doesn't compile, as it performs

Adding a callback to a variadic template class - impossible?

大城市里の小女人 提交于 2019-12-13 01:05:29
问题 I'm trying to make a templated class, which has an Add method, that attaches a function callback to the class, so when I can then call it from there with the specified arguments list.It compiles fine, except for the part where I invoke the callback.It just doesn't accept the arguments, I've tried everything I can think of, but it still gives me the same "cannot expand parameter pack" error.Im using Visual Studio 2012 with the Microsoft Visual C++ Compiler Nov 2012 CTP (v120_CTP_Nov2012) Here

c++ scalable grouping of lambda functions in blocks of an arbitrary number

夙愿已清 提交于 2019-12-12 23:05:36
问题 I have to execute several lambda functions, but every each N lambdas a prologue() function also must be run. The number of lambdas can be arbitrary large and N is known at compile time. Something like this: static void prologue( void ) { cout << "Prologue" << endl; } int main() { run<3>( // N = 3 [](){ cout << "Simple lambda func 1" << endl; }, [](){ cout << "Simple lambda func 2" << endl; }, [](){ cout << "Simple lambda func 3" << endl; }, [](){ cout << "Simple lambda func 4" << endl; }, [](

How can the “min” type be found in a variadic parameter pack?

爱⌒轻易说出口 提交于 2019-12-12 19:31:23
问题 By "min" type, I mean the type compared less than all according to a compile time function, eg sizeof I have a draft implementation, will present it first and refer to the two problems I'm facing: #include <iostream> #include <typeinfo> #include <type_traits> using namespace std; // Unspecialized version template<typename...Ts> struct Tmin { using type = void; }; template<typename T> struct Tmin<T> { using type = T; }; template<typename T1, typename T2, typename...Ts> struct Tmin<T1, T2, Ts..

Are there any reasons why c++ template packs are passed using std::tuple

时光毁灭记忆、已成空白 提交于 2019-12-12 18:51:39
问题 Let's say we want to create a helper class to reverse template pack e.g. as follows: #include <tuple> #include <utility> #include <typeinfo> #include <iostream> template <class> struct sizer; template <template<class...> class Pack, class... Args> struct sizer<Pack<Args...>> { static constexpr size_t value = sizeof...(Args); }; template <class Pack, class Indices = std::make_index_sequence<sizer<Pack>::value>> struct reverse_pack; template <class... Args, size_t... I> struct reverse_pack<std:

Templated Multi-Dimensional Arrays

你离开我真会死。 提交于 2019-12-12 18:46:00
问题 I'm trying to experiment with templates and tried to implement templated arrays, something that can be declared like: Array!(float, 3, 2, 1) myArray; I've browsed through several implementations of this problem in C++ but I can't seem to convert it to D as I have little experience with the language (with D). Anyways these are the stuff I tried, unfortunately none of them worked: 1. Compile-Time Functions - to generate code of the format "DataType[D0][D1]...[Dn] Identifier" import std.conv;

Do Variadic Template Parameters Always Have to be Last?

假装没事ソ 提交于 2019-12-12 18:39:21
问题 Do I always have to place variadic template parameters at the end of my template parameters? template <size_t begin = 0U, typename... Tp> void foo(tuple<Tp...> t); For example I get all kinds of errors with this: #include <functional> #include <iostream> #include <string> #include <tuple> using namespace std; template <typename... Tp, size_t begin = 0U> enable_if_t<begin == sizeof...(Tp), void> foo(tuple<Tp...>& t){ cout << endl; } template <typename... Tp, size_t begin = 0U> enable_if_t

Find out how this variadic templated function works

萝らか妹 提交于 2019-12-12 17:15:56
问题 In this answer I have seen some C++11 code, that I don't really understand (but I would like to). There, a variadic template function is defined, that (maybe?) takes all arguments passed and inserts them into a std::ostringstream . This is the function (see the complete working example at the linked answer): template<typename T, typename... Ts> std::string CreateString(T const& t, Ts const&... ts) { using expand = char[]; std::ostringstream oss; oss << std::boolalpha << t; (void)expand{'\0',