type-deduction Questions
1
Solved
I recently noticed a strange issue regarding C++23 Deducing this feature.
Suppose we have a struct S with a simple conversion operator:
struct S {
operator int() { return 42; }
};
int i = S{};
S...
Virescent asked 28/1 at 11:55
1
Solved
How do I get the return type of a lambda that has a deducing this signature using std::invoke_result_t.
auto lambda = [](this auto& self, int x) -> int {
return x;
};
auto x = std::invok...
Handlebar asked 5/9, 2023 at 7:9
1
Should the compiler be able to deduce the type of the non-type template parameter of function template f that is defaulted to n{}? Which specific rule in the C++20 standard allows/mandates this?
te...
Orangeism asked 29/7, 2023 at 23:53
2
Solved
template <typename T>
struct X
{
template <typename Iter>
X(Iter a, Iter b) {}
template <typename Iter>
auto f(Iter a, Iter b)
{
return X(a, b);
}
};
In the "C++ Templat...
Alfons asked 3/7, 2018 at 7:33
3
For example:
map (+1) 2
in ghci yields
<interactive>:23:1: error:
* Non type-variable argument in the constraint: Num [b]
(Use FlexibleContexts to permit this)
* When checking the infer...
Alvord asked 15/3, 2020 at 16:20
2
Solved
I have a struct with a method called call which has a const overload. The one and only argument is a std::function which either takes a int reference or a const int reference, depending on the over...
Vociferant asked 8/4, 2022 at 12:29
1
Solved
#include <type_traits>
int x = 0;
void f(int const x)
{
static_assert(std::is_const_v<decltype(x)>); // ok
}
int main()
{
int n = 0;
[n, m = n]
{
static_assert(std::is_const_v&l...
Thursday asked 26/6, 2021 at 13:6
1
Solved
template<typename T>
concept Octet = 1 == sizeof(T);
// ok
Octet decltype(auto) c = 'a';
// ok
void f1(const auto&) {}
// ok
void f2(Octet auto) {}
// ok
void f3(Octet auto&&)...
Nitpicking asked 7/5, 2021 at 18:14
1
Solved
struct A
{
auto g1()
{
return true;
}
void f()
{
if (auto b = g1(); b) // ok
{
return;
}
if (auto b = g2(); b) // error: use of 'auto A::g2()' before deduction of 'auto'
{
return;
}...
Obstacle asked 6/5, 2021 at 12:21
2
Solved
The title might seem a little confusing, so here is a more thorough explanation:
I have a templated class that has a vector as a member variable. The template argument is a struct (or class) that w...
Mot asked 3/5, 2021 at 9:46
1
Solved
(This question has been broken out from the discussion to this answer, which highlights CWG 1892)
Some paragraphs of the standard applies specific rules to function declarators; e.g. [dcl.spec.aut...
Betterment asked 2/2, 2021 at 11:42
3
Solved
I have the following code sample:
template<typename T>
void print(T t) {
std::cout << t << std::endl;
}
template<typename Key, typename Value, typename F>
void traverse(st...
Service asked 5/9, 2020 at 13:39
1
Solved
I'm working with std::variant and std::visit using the "overload" pattern that looks like this:
#include <iostream>
#include <variant>
template<class... Ts> struct over...
Hubing asked 13/7, 2020 at 3:10
2
Solved
When I have a member function marked as const and inspect the types of the member variables I get some results I don't expect.
#include <iostream>
#include <string>
template<typena...
Gaelic asked 10/6, 2020 at 13:30
1
Solved
I'm trying to provide a wrapper around std::invoke to do the work of deducing the function type even when the function is overloaded.
(I asked a related question yesterday for the variadic and meth...
Libyan asked 8/3, 2020 at 6:25
1
Solved
I'm trying to use auto to automatically deduce the type of a nested std::initializer_list.
auto list = {
{{ 0, 1}, { 2, 3 }},
{{ 4, 5}, { 6, 7 }},
};
The actual type here is std::initializer_lis...
Thora asked 24/12, 2019 at 16:33
2
Solved
So, I am trying to implement the dot product (https://en.wikipedia.org/wiki/Dot_product) in some flavour of modern C++ and came up with the following code:
#include <iostream>
template<c...
Dru asked 14/11, 2019 at 11:21
4
Solved
In the snippet below, auto deduces the variable to double, but I want float.
auto one = 3.5;
Does it always use double for literals with a decimal point? How does it decide between float a...
Painterly asked 16/8, 2019 at 5:32
2
Solved
Both from my personal experience and from consulting answers to questions like What are some uses of decltype(auto)? I can find plenty of valuable use cases for decltype(auto) as a function return ...
Airport asked 9/8, 2019 at 23:40
4
Solved
Consider this minimal example
template <class T>
class Foo
{
public:
Foo(const T& t_)
: t(t_)
{
}
Foo(T&& t_)
: t(std::move(t_))
{
}
T t;
};
template <typename F&g...
Caesura asked 1/8, 2019 at 15:26
2
Solved
Visual Studio doesn't see the right constructor when I instantiate the template class. Where did I make a mistake?
I've already tried to make copy/move constructors explicit/deleted. Doesn't help....
Celestina asked 1/8, 2019 at 13:53
1
Take a look at this code using the docopt library:
const USAGE: &'static str = "...something...";
#[derive(Deserialize)]
struct Args {
flag: bool,
}
type Result<T> = result::Result<...
Longrange asked 26/2, 2019 at 11:47
2
Solved
I'm trying to deduce the types of a class's constructor's parameters. I've succeeded in getting the parameter types for member methods but my approach fails for constructors because it relies on ge...
Disney asked 12/1, 2017 at 22:10
1
Solved
#include <type_traits>
int main()
{
int arr[1] = { 6 };
auto& ref1 = arr[0];
static_assert( std::is_same_v<decltype( ref1 ), int&> ); //ok
auto& [ ref2 ] = arr;
sta...
Farrow asked 24/11, 2018 at 19:22
1
I've a simple template function do_something which returns an integer: 123.
template<typename T>
auto do_something(T input) {
std::this_thread::sleep_for(std::chrono::seconds(1));
return...
Eshman asked 4/7, 2016 at 0:9
1 Next >
© 2022 - 2024 — McMap. All rights reserved.