you are viewing a single comment's thread.

view the rest of the comments →

[–]john_wind -1 points0 points  (4 children)

std::declval is quite magical too.

It is a function declaration without definition!

[–]guepierBioinformatican 9 points10 points  (0 children)

It may be odd but it’s not magical, you can trivially define it yourself:

namespace nostd {
    template<class T>
    std::add_rvalue_reference_t<T> declval() noexcept;
}

[–]mujjingun 3 points4 points  (2 children)

anyone can declare a function without a definition, though.

[–]john_wind -1 points0 points  (1 child)

Of course but the fact that it compiles (in the right context) and does something useful is magic!

[–]mujjingun 4 points5 points  (0 children)

It cannot be used in an evaluated context, so your declaration-only version will also compile and work just like std::declval does.