36 questions
2
votes
3
answers
130
views
How to take a pointer to a declval?
It says that the address of operator must be on an lvalue which I don't think the result of declval is:
template <typename T>
void test_serialisation(T* t)
{
constexpr bool can_serialise = ...
3
votes
2
answers
104
views
Cannot detect protected base class method with SFINAE
I attempted the following approach using c++ SFINAE and std::declval to find if there exists the proper method in a base class, that can be called from the derived class. The derived class gets the ...
3
votes
1
answer
120
views
Why doesn't this requires clause return true when using declval?
I'm trying to use a requires clause, and it only works if used on an actual concrete object passed as an argument to a function, but not one given by declval:
struct ImageMipInfo
{
ImageMipInfo() {...
1
vote
0
answers
111
views
How to specify (declval?) a function pointer argument to a method in a concept 'requires' block?
I have a scheduler class template that I'd like to use with one of several timer classes. I'd like to use a concept to verify a given timer class has what the scheduler needs.
// One of several that ...
3
votes
1
answer
397
views
How does `decltype(true ? std::declval<T1>() : std::declval<T2>())` works?
I saw the example code for template function max.
template <typename T1,
typename T2,
typename RT = std::decay_t<decltype(true ? std::declval<T1>()
...
-1
votes
1
answer
123
views
Understanding declval function a little further
I just learn the declval keyword in c++ and I was wondering why in the following code (std::add_rvalue_reference<Foo>::type).constFunc7() x = 3; is not compiling. Isn't it the same thing as ...
1
vote
1
answer
220
views
error: use of 'decltype(auto) X before deduction of 'auto' (for generated lambda)
I'm trying to hammer down the type of a this-capturing lambda using a special generating member function with decltype(auto). However, the compiler resists to determine the lambda's type for the ...
8
votes
1
answer
429
views
Is it legal to use std::declval in lambda in unevaluated contexts?
Code as below or on godbolt compiles with gcc and MSVC but fails with clang. I couldn't find if/where it is forbidden in the standard. In my opinion it should be supported.
So who is correct on this, ...
3
votes
1
answer
845
views
Type trait to check if istream operator>> exists for given type
I found this type trait which can be used to check if a certain type T supports operator<<:
template<class Class>
struct has_ostream_operator_impl {
template<class V>
static ...
1
vote
1
answer
323
views
How to check copy assignment operator in c++ in noexcept() function
I try to check template class T in function do_math() on the possibility of throwing an exception in the copy assignment operator.
But the following code throws an error:
template<class T>
void ...
8
votes
1
answer
1k
views
std::reference_wrapper, constructor implementation explaination
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 { ...
1
vote
1
answer
1k
views
What is meant by the statement that std::declval cannot be called?
On the cppreference-page for std::declval it says the following:
Return value
Cannot be called and thus never returns a value.
What does this mean? Surely we call it when we use it?
struct Foo { int ...
2
votes
0
answers
261
views
static assertion on noexcept for protected constructors
I'm attempting to assert following protected class constructors may or may not throw as follows:
#include <utility>
#include <type_traits>
class X
{
protected:
X() noexcept(false) { }
...
1
vote
0
answers
198
views
Why isn't std::declval<int>() an lvalue when std::declval<int&>() is?
The first of these two lines fails to compile, the second compiles in MSVC 2017:
// std::cout << sizeof(decltype(++std::declval<int>())) << "\n"; //error. expression ...
6
votes
3
answers
262
views
Is std::declval outdated because of guaranteed copy elision?
The standard library utility declval is defined as:
template<class T> add_rvalue_reference_t<T> declval() noexcept;
To add a rvalue reference here seemed like a good idea, if you think ...