Class Template Argument Deduction, introduced in C++17, allows deducing missing template arguments for class template instantiation based on the initializer.
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…
Clang and GCC disagree on accepting this code.
What is the standard required behavior?
#include
#include
#include
int main()
{
std::vector pairs = {std::pair{1,11},{2,22}, {3,33}};
for (const auto& p: pairs) {
…
#include
int main()
{
auto v = std::vector{std::vector{}};
return v.front().empty(); // error
}
See online demo
However, according to Scott Meyers' Effective Modern C++ (emphasis in original):
If, however, one or more…
I have already stated confusion about CTAD with designated initializers in this question, but i have another confusion with a very similar code snippet
template
struct my_pair {
int_t first;
…
Q1 : Are user-defined deduction guides allowed at namespace scope ?
In the example here, GCC and Clang does not produce the same behavior :
https://godbolt.org/z/8W6hznEjo
#include
template
struct some_type;
template…
Since C++11, to move append some vector y to another vector x, you can do:
x.insert(x.end(), std::make_move_iterator(y.begin()), std::make_move_iterator(y.end()));
With C++17 class template argument deduction it is possible to write this a bit more…
This code works, without having to specify a constructor:
struct Foo
{
int a;
int b;
};
//...
int a1, b1;
Foo foo = {a1, b1};
If I make Foo a template, it doesn't work.
template
struct Foo
{
T1 a;
…
Why does the following CTAD attempt fail to compile ?
template struct C { C(T,T) {} };
template <> struct C { C(int) {} };
C c(1); //error: template argument deduction failure
I would have expected that the constructor C(int)…
In C++20, alias templates can have implicit deduction guides if it is applied.
Then, I have constructed a simple template alias which is ints:
template
using ints = std::array;
but:
ints{1, 2, 3, 4}
doesn't work, and GCC…
The following snippet compiles in gcc 12.1 but not in gcc 11.1. Unfortunately, I only have gcc 11 at hand as I'm crosscompiling for a microcontroller. Is there a way to make it work? Also what is this cryptic "use 'auto' for an abbreviated function…
According to P1814R0, the template deduction should work for alias with default value. With GCC 12.2(-std=c++20), the following code built successfully. However, in MSVC v19.33(/std:c++20) (which supports P1814R0), I got an error
(10): error…
I am trying to write a vector wrapper (indexed_vec) which stores objects of type ValueType but other datastructures (vectors of other types) refer to these by index (because iterators are clearly not stable).
So when objects of ValueType are deleted…