All Questions
Tagged with constructor templates
503
questions
0
votes
2
answers
36
views
Issue calling a variadic template constructor
The following code doesn't work, it fails because it cannot find a constructor with a <int, bool> signature.
I know can't specify explicitely the template parameters in the case of a constructor....
0
votes
1
answer
78
views
Using SFINAE in constructor, to check if constructor of a member type exists
#include <string>
#include <type_traits>
struct A {
A(int) {}
};
template<typename... Args>
auto make_A(const Args&... args) -> decltype(A(args...)) {
return A(args.....
0
votes
1
answer
40
views
Explicitly specialize templated constructor with zero arguments [duplicate]
Suppose the following class:
class JsonDocument
{
public:
using RootType = size_t;
constexpr static RootType ObjectRoot = 1;
constexpr static RootType ArrayRoot = 2;
template<
...
-2
votes
1
answer
53
views
How to instantiate template constructor in template class/struct in C++ [duplicate]
I have a template struct with template constructor:
template<typename F>
struct Vector2
{
template<typename F1>
Vector2(const Vector2<F1>& vector);
};
Implementation for ...
0
votes
1
answer
39
views
julia parametric constructor
Suppose I write the following julia struct:
struct Foo{S, T}
v::Vector{S}
t::T
end
If I want v to be empty by default, I can write a custom constructor
Foo{Int, String}(t::String) = Foo{Int, ...
0
votes
1
answer
78
views
Constructor templates in a nontemplate class C++
I have a non-template class (Uart) and want to create template constructor. It needs to take another template class object (SafeQueue). Then this constructor will call another template function ...
0
votes
1
answer
152
views
How to define a seperate implementation of a template class constructor [duplicate]
I am working with an old code in C++ that uses a custom implementation of a matrix class.
The matrix is class is implemented as a template class. The declaration looks like this
/**********************...
2
votes
1
answer
48
views
Conditionally allow supply of allocators to wrapped objects
I'm creating a container that can be templated on the string type it uses for its members, either it's an owning or non-owning string (std::string vs std::string_view). For the case of the non-owning ...
0
votes
0
answers
69
views
In c++, how to define a template class' nested class constructor, that takes a sibling class for parameters?
Given example DirectedGraph:
What is the definition of the two nested class' constructors? Based on my observation below, I am guessing it has to do with the constructor's parameters being a sibling ...
3
votes
3
answers
92
views
parameter pack templated constructor deletes copy assignment
Trying to understand why having a parameter pack templated constructor for a class apparently causes both the copy constructor and the copy assignment operator to be optimized out. (Actually I can ...
4
votes
2
answers
139
views
Class constructor compiles on clang but rejected on gcc
I am learning about constructors in C++. In particular, that a C++ class can have more than one constructor. But then I made the following program that worked with clang but not with gcc and msvc.
...
3
votes
1
answer
55
views
How to call a specialized struct template without providing the chevron info?
To be my question more clear, firstly I show you my templated struct State to describe the state vector of a state space according to the dimension :
template<unsigned int Dimension>
struct ...
2
votes
3
answers
87
views
Avoid template mess when importing base class constructors of heavily templated base class
This is just short inquiery if it is at all possible to somehow import base class constructors without all the template bloat. Consider this example where I'm inheriting from a templated std::variant:
...
0
votes
1
answer
175
views
Enabling C++ constructor subject to say std::is_floating_point<T>
I'm trying to enable a default constructor only if the class's template
parameter is floating point. Note T is not a parameter type nor return type
but the class template type.
template <typename T&...
1
vote
0
answers
22
views
Other form of nested templates in C++ [duplicate]
I have a class template declaration:
template<class T>
class MyClass
{
private:
std::vector<T> m_data;
public:
MyClass();
template<typename U>
MyClass(const U& ...