c++17

Template Alias, Variable Template, and auto type deduction failing to deduce template argument

安稳与你 提交于 2019-12-24 19:35:47
问题 While working on my class declaration I'm having some confusion on how to use alias templates and template variables within in a non class template while trying to use auto type deduction. Signal.h #ifndef SIGNAL_H #define SIGNAL_H #include <cstdint> template<typename T> using TimeSignal = T; using DiscreteTime = TimeSignal<std::uint8_t>; using ContinuousTime = TimeSignal<double>; class Signal { private: template<typename T> static TimeSignal<T> time_; double voltage_; double current_; public

Visual Studio 2017 - could not deduce template argument (with variadic templates)

纵然是瞬间 提交于 2019-12-24 17:22:50
问题 The following code compiles and works fine in gcc and clang, but fails to compile in Visual Studio 2017.7 (x86-64): #include <vector> #include <iostream> #include <type_traits> template <template <typename...> class> struct isVector : public std::false_type { }; template <> struct isVector<std::vector> : public std::true_type { }; // Other isVector specializations (for QVector<T>, etc...) // ... // A function accepting vector<vector<double>> template < template<typename ...> class V1,

boost::mpi and boost:serialization with std::variant

自古美人都是妖i 提交于 2019-12-24 16:48:05
问题 c++17 introduces the new type std::variant . Is it possible to define a serialization routine, so as to use std::variant in conjunction with boost::mpi ? Consider, e.g., a simple program #include <variant> #include <boost/mpi.hpp> #include <boost/serialization/string.hpp> namespace mpi = boost::mpi; class A { friend class boost::serialization::access; template <class Archive> void serialize(Archive& ar, const unsigned int version) { ar & x; ar & y; } public: int x, y; }; class B { friend

why this variable isn't deduced as initializer_list in g++ in C++14?

拜拜、爱过 提交于 2019-12-24 15:04:54
问题 Consider the following program: #include <iostream> int main() { int n = 3; int fact = 1; for(auto i{1};i<=n;i++) fact*=i; std::cout<<"fact of "<<n<<" is "<<fact; } It compiles fine on ideone even when I use -std=c++14 option. See live demo here. But in C++14 the variable i should be deduced as initializer_list according to this. There is a proposal for C++1z that implements new type deduction rules for brace initialization: For direct list-initialization: For a braced-init-list with only a

Create a family of template classes convertible to each other

╄→гoц情女王★ 提交于 2019-12-24 14:58:05
问题 I want to create a family of template classes, where each of them would derive from common base. This common base would define, how to convert instance of one of these derived classes to any other. I have created base class template with both copy constructor and copy assignment operator, here is the code: template < class T > struct class_family { T data; class_family() = default; class_family(const class_family& a) : data(a.data) { } class_family& operator=(const class_family& a) { data = a

Check that signature of two functions or member function pointer equal

三世轮回 提交于 2019-12-24 14:03:12
问题 I write some code for check that signature of free function is equal to signature of member function, etc. It compare extracted return type and function arguments: #include <tuple> #include <type_traits> template<class Signature> struct signature_trait; template<class R, class... Args> struct signature_trait<R(Args...)> { using return_type = R; using arg_types = std::tuple<Args...>; }; template<class R, class... Args> struct signature_trait<R(*)(Args...)> { using return_type = R; using arg

Work with unique_ptr<int[]>, vector<int>, and int[] in a Templatized Function

こ雲淡風輕ζ 提交于 2019-12-24 12:06:10
问题 Say that I have 3 variables: vector<int> vec(3); int stat[3]; auto dyn = make_unique<int[]>(3); I can initialize any of these if I know the size is 3: for(auto i = 0; i < 3; ++i) X[3] = i; Where X is either, vec , stat , or dyn . But I'd like to be able to do this in a template just by passing in X again. What I'd need in order to do this is: The contained type The container size Can I get that in a function like: template <typename T> void init(T& X); Or am I unable to extract size

How to pass a member function as a parameter? (PortAudio)

为君一笑 提交于 2019-12-24 10:38:22
问题 I am trying to create multiple streams in portaudio. This is what it requires for opening a stream PaError Pa_OpenDefaultStream( PaStream** stream, int numInputChannels, int numOutputChannels, PaSampleFormat sampleFormat, double sampleRate, unsigned long framesPerBuffer, PaStreamCallback *streamCallback, void *userData ); and this is the PaStreamCallback function. typedef int PaStreamCallback( const void *input, void *output, unsigned long frameCount, const PaStreamCallbackTimeInfo* timeInfo,

Recursively folding a parameter pack to resolve placeholder types

不打扰是莪最后的温柔 提交于 2019-12-24 10:37:49
问题 Notice: Followup to this question After asking this question about parameter pack folding into pairs, I noticed that I need to retain the complete type of the previously folded type as the left pair type. For example: Fold<char, int, long, double> f; must evaluate to std::tuple< std::pair<char , int>, std::pair<std::pair<char, int> /* <-- the previous resulting type */ , long>, std::pair<std::pair<std::pair<char, int>, long> /* the previous type again */ , double> > f; Context to this problem

Class member function template partial specialization with variadic parameters [closed]

限于喜欢 提交于 2019-12-24 10:27:37
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed last year . I'm using Visual Studio 2017 CE version 15.6.2 with compiler language options set to: ISO C++ Latest Draft Standard (/std:c++latest) I'm working with a majority of the functions from <random> and I have 2 classes that are non template classes, RandomEngine and RandomDistribution . These classes can not be