Category : template-templates

I have std::vector<double> , and my type Array-like. Also, there are a lot of numbers in std::vector<double> source, and I would like to make this code work in the way: std::cout << toHisto(source, /* other parameters like min, max, stacks */); And I guessed that would be good, if the function toHisto worked with other ..

Read more

My goal is to be able to compare templates i.e. write something like this template<typename T> struct template_type; template<template <typename…> typename TTmpl, typename …Ts> struct template_type<TTmpl<Ts…>> { using type = TTmpl; }; // [1] this isn’t valid C++ template<typename TRng, typename T> auto find(TRng&& rng, const T& val) { using TTmpl = typename mcu::template_type<std::remove_const_t<std::remove_reference_t<TRng>>>::type; if ..

Read more

I’m planning to create a variable template that takes (variable) template-template parameter and one typename: template <template <typename> auto MetaPredicate, typename T> constexpr bool has_predicate_v_ = requires { { MetaPredicate<T> } -> std::convertible_to<bool>; } Where the expectations are: template <typename T> struct dummy_01 { inline static constexpr bool value = true; }; template <typename T> ..

Read more

I’m trying to understand under what circumstances I can pass a type template as an argument for a template template parameter with a different signature. E.g., I would expect that the following might compile successfully. template <typename…> struct foo { }; template <template <typename> typename Template> struct bar { }; using quux = bar<foo>; After ..

Read more

The following snippet of C++17 code compiles in GCC and CLang, but in Visual C++ it gives the error C2784: Could not deduce template argument. https://godbolt.org/z/o4fe351Kn #include <iostream> #include <vector> template< template <typename…> typename container > std::ostream & f (std::ostream & out, const container< int > &) { return out; } std::ostream & operator << ..

Read more