All the std::make_ are made redundant by C++17 with the introduction of Class template argument deduction (except make_unique and make_shared).
So what is the point of std::make_optional? As far as I can tell it does the exact same thing as the…
With C++20, it is possible to have deduction guidelines generated for an alias template (See section "Deduction for alias templates" at https://en.cppreference.com/w/cpp/language/class_template_argument_deduction). Yet, I could not make them work…
In the C++ 17 and C++ 20 Working Drafts of the C++ Standard the deduction guide for the class template std::array is defined the following way
template
array(T, U...) -> array;
As a result for example this…
For some reasons, I've always thought that deduction guides must have the same noexcept-ness of the constructor to which they refer. For example:
template
struct clazz {
clazz(const T &) noexcept {}
};
clazz(const char &) noexcept…
I want to make an NDArray template which has a fixed dimension, but can be resized across each dimension.
My question is how to make it be able to deduce the dimensions in the constructor according to how many pair of {} is used? The elements in the…
Suppose I want to make a new deduction guide making the following possible ?
std::string str;
std::basic_string_view sv = str;
Would that be an Ok customization ?
I'm writing a deduction guide in the style of an abbreviated function template, but I'm not sure if it's allowed. It compiles on gcc and clang, but not msvc.
The error is:
error C3539: a template-argument cannot be a type that contains…
std::basic_string's deduction guides allow the user to use the std::basic_string name without specifying its template parameters. Users are also allowed to create their own deduction guides. Assume that the user wants to recreate std::basic_string.…
I am reading about deduction guides in C++17. So say we have the following example:
template struct Custom
{
};
template struct Person
{
Person(Custom const&);
Person(Custom&&);
};
template…
Consider the following code:
template
struct D : B { };
D d{[]{ }};
gcc 12.x accepts it and deduces d to be D* type of lambda */> as expected.
clang 14.x rejects it with the following error:
:4:3: error: no viable…
I have the beginnings of a matrix class. Here's the code-
template
class mat {
public:
mat() : values(h, std::vector(w)) {
if (w == h) {
int x = 0;
for (int y = 0; y < h; y++) {
…
I have a class template:
template
class iterator
{
explicit iterator(T*);
};
I tried using the c++17 feature Class template argument deduction (CTAD) to deduce T, but I can't do so, since there is no way to deduce N…
Suppose I have a class/struct template together with an explicit deduction guide for its constructor. Let this class have two template parameters of which one can get deduced by the deduction guide, for the other it can not.
template
This post already explains how adding deduction guides in the std namespace is undefined.
Now, what I would really like to do is this:
namespace std { // undefined behavior
template
array(char const*, U...) -> array