ctad Questions
1
Solved
I have this class
template <typename ValueType, std::size_t Size>
struct ArrayPrimitive
{
constexpr ArrayPrimitive(const ValueType (&array)[Size]) {
std::copy(array, array + Size, data_...
Chasidychasing asked 3/9, 2023 at 14:29
1
Solved
#include <boost/type_index.hpp>
#include <iostream>
#include <vector>
int main()
{
std::vector v{2, 3.14};
std::cout << boost::typeindex::type_id_with_cvr<decltype(v)&...
6
Solved
If I am allowed to do the following:
template <typename T = int>
class Foo{
};
Why am I not allowed to do the following in main?
Foo me;
But I must specify the following:
Foo<int>...
Trisyllable asked 12/3, 2013 at 22:52
1
Solved
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<typename...
Boric asked 19/1, 2022 at 7:16
1
Why does the following CTAD attempt fail to compile ?
template <typename T> struct C { C(T,T) {} };
template <> struct C<int> { C(int) {} };
C c(1); //error: template argument de...
Hough asked 15/1, 2022 at 7:46
2
Solved
#include <vector>
int main()
{
auto v = std::vector{std::vector<int>{}};
return v.front().empty(); // error
}
See online demo
However, according to Scott Meyers' Effective Modern C+...
Aida asked 30/8, 2021 at 7:18
1
Solved
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 <tuple>
...
1
Solved
Clang and GCC disagree on accepting this code.
What is the standard required behavior?
#include <utility>
#include <iostream>
#include <vector>
int main()
{
std::vector pairs = ...
Gable asked 9/2, 2021 at 18:19
2
Solved
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...
Trinitrotoluene asked 4/7, 2020 at 22:1
2
Solved
I am trying to write a deduction guide, that only detects one of many typename's from given constructor argument and requires user to enter int size manually
template <int size, typename ...
Stew asked 28/5, 2019 at 23:11
2
Example:
namespace X{
inline namespace Y{
template<typename T>
struct A{
};
}
}
namespace X{
template<typename Z>
A(std::vector<Z>) -> A<Z>;
}
This causes a compi...
0
Given the following module
// mod.cpp
export module mod;
export template<typename T>
struct something
{
constexpr something(T){}
};
export template<typename T>
constexpr auto make_...
Infusive asked 24/3, 2020 at 9:12
1
Solved
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 <typename int_t=int, typename fl...
Thema asked 11/9, 2019 at 9:58
1
Solved
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 argu...
2
Solved
In the example below, we use the C++17 feature "Class template argument deduction" to deduce that val is of type Base<int, double, bool>:
template<class T, class U, class V>
struct Bas...
Pasquale asked 19/8, 2019 at 20:33
2
Solved
Why does make_pair and Class Template Argument Deduction (CTAD) not agree on which type to generate?
#include <iostream>
#include <functional>
#include <utility>
#include <typ...
Andizhan asked 26/11, 2018 at 14:20
1
Solved
I have the following piece of C++17 code that uses class template deduction:
template <typename T>
struct Test {
T t;
Test(T t) : t(t) {}
bool check() { return true; }
};
template ...
Eloisaeloise asked 22/11, 2018 at 16:59
3
Solved
I just watched Stephan T. Lavavej talk at CppCon 2018 on "Class Template Argument Deduction", where at some point he incidentally says:
In C++ type information almost never flows backwards ... I...
Whittier asked 12/11, 2018 at 21:16
1
Solved
Consider the following code snippet:
template <typename T>
struct foo
{
foo(T) { }
};
int main()
{
foo{0};
}
g++ 7 happily creates a temporary object of type foo, deducing T = int.
cla...
Wynn asked 3/12, 2017 at 0:26
2
Solved
My understanding about the P0091: Template argument deduction for class templates proposal was to homogenize the behavior of function templates and class templates in deduction contexts, but I thi...
Pharmacist asked 24/1, 2017 at 16:40
2
Solved
consider the code pasted below. I have defined a very simple class, for which the compiler generates an implicit deduction guide so it can be constructed without explicit template arguments. Howeve...
1
Solved
The C++17 standard introduces "template deduction guides". I gather they're something to do with the new template argument deduction for constructors introduced in this version of the standard, but...
Sherlocke asked 3/12, 2016 at 19:35
1
© 2022 - 2025 — McMap. All rights reserved.