decltype Questions
2
Using -std=c++23, gcc accepts the following code while clang rejects it:
struct outer {
struct {
int x;
inline int get_x() const;
} inner;
};
inline int
decltype(outer::inner)::get_x() const
{...
Jabot asked 27/7, 2024 at 9:26
4
Solved
I'm trying to declare a variable so that its type is the same as the return type of a member function to which I have a member function pointer.
class Widget {
public:
std::chrono::milliseconds ...
Argumentum asked 21/3, 2015 at 16:15
5
Solved
I have a number of classes that I cannot modify. Each has a copy constructor, at least one other constructor, and a function foo() that returns some value. I want to make a class template that can ...
0
The following program which uses auto arguments to generate function templates and then explicitly instantiates them will compile fine in g++ and clang (x86-64 trunk, -std=c++20) but gives errors C...
2
When using decltype,
is it permissible to use the traditional leading return type syntax in a
declaration:
decltype(expr) foo();
and then use
C++11 trailing return type
syntax in the definition?
...
Decompensation asked 7/8, 2023 at 5:43
2
Solved
#include <iostream>
#include <type_traits>
int main(){
int i = 1;
int& j = i;
auto f2 = [j = j]() {
std::cout
<< std::is_same_v<decltype(j), int&>
<< ...
Gibraltar asked 14/7, 2023 at 15:57
1
Solved
I'm trying to define a static variable of a templated class outside of the class scope using clang:
class Bar
{
public:
float a;
};
template<long count>
class Foo {
public:
static Bar* tes...
1
The title should clarify what my confusion is about. I'd like to use this question to get a comprehensive answer which helps me understand how the comma operator works with decltype within SFINAE c...
Sphagnum asked 28/9, 2021 at 18:11
2
Solved
I came to know that for a class X with a member function named func, the c++ standard doesn't allow us to write decltype(X::func). Thus I expected the below given program to produce an error saying...
Carver asked 7/5, 2023 at 4:9
2
Solved
I would like to obtain a type in a variadic template by index. The index is specified as a template argument.
I managed to find a 'hack' that works, but I believe that it is not in the spirit of va...
Footpad asked 19/4, 2015 at 11:1
1
Solved
Usually decltype perseveres the ref qualifiers
auto a = 0;
auto& a_ref = a;
static_assert(std::is_reference_v<decltype(a_ref)>);
But apparently not when it's argument is obtained f...
Uri asked 28/9, 2022 at 23:8
2
Solved
I'm new at programming and can someone explain to me how this code work?
#include <iostream>
using namespace std;
int main () {
int a = 3, b = 4;
decltype(a) c = a;
decltype((b)) d = a;
...
6
Solved
As I understand it, both decltype and auto will attempt to figure out what the type of something is.
If we define:
int foo () {
return 34;
}
Then both declarations are legal:
auto x = foo();
cout...
Encephalitis asked 23/8, 2012 at 2:41
2
In https://github.com/stlab/libraries/blob/main/stlab/concurrency/main_executor.hpp, I read
struct main_executor_type {
using result_type = void;
template <typename F>
void operator()(F f...
3
Solved
I came across the following code:
template <typename T, typename T1> auto compose(T a, T1 b) -> decltype(a + b) {
return a+b;
}
There is one thing I cannot understand:
Where could I find...
1
Solved
Question
Consider the following struct:
template<typename T>
struct stream
{
using type = decltype(
std::declval<std::ostream>() << std::declval<T>()
);
};
template<...
1
Solved
I have been trying to understand the implementation of std::reference_wrapper, from here, which is as follows:
namespace detail {
template <class T> constexpr T& FUN(T& t) noexcept { ...
Mould asked 2/1, 2022 at 23:58
1
Solved
Let's say we have a class template Foo, that has one type template parameter that it can deduce from an argument in its constructor. If we use std::make_unique to construct an instance of Foo, is t...
Fungal asked 10/12, 2021 at 22:2
1
The 2nd edition of C++ Templates - The Complete Guide features the following footnote at page 436 (my bold):
Except that decltype(call-expression) does not require a nonreference, non-void return ...
Agnola asked 27/9, 2021 at 20:4
1
Solved
The 2nd edition of C++ Templates - The Complete Guide features the following code at page 435
#include <string>
#include <type_traits>
template<typename T, typename = void>
struc...
4
Solved
I know about value_type, key_type... but they operate on types, not on instances.
I tried
stuff like :
std::set<uint64_t> mySet;
decltype (mySet)::value_type pos;
But it doesnt work.
...
3
when reading about auto and decltype (C++11) i see the below function
auto findMin(A a, B b) -> decltype(a < b ? a : b)
{
return (a < b) ? a : b;
}
this part -> decltype(a < b ? a ...
Loner asked 16/6, 2021 at 4:12
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
3
Solved
Both gcc and clang accept the following code, and I'm trying to figure out why.
// c++ -std=c++20 -Wall -c test.cc
#include <concepts>
struct X {
int i;
};
// This is clearly required by ...
Bencion asked 8/6, 2021 at 7:2
1
Solved
Consider the following demonstrative program.
#include <iostream>
namespace N
{
struct A
{
static int n;
};
A A;
}
int N::A::n = 10;
int main()
{
std::cout << N::A::n <&l...
Apeak asked 7/5, 2021 at 13:30
1 Next >
© 2022 - 2025 — McMap. All rights reserved.