Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does a function call give a compile-time type?

#include <range/v3/all.hpp>

using namespace ranges;

template<typename I, typename O>
tagged_pair<tag::in(I), tag::out(O)>
f(I i, O o)
{
    return { i, o };
}

int main()
{
    char buf[8]{};
    f(std::begin(buf), std::end(buf));
}

The code uses range-v3 and can be compiled with clang.

However, I cannot understand why the line tagged_pair<tag::in(I), tag::out(O)> is legal. I is a type, tag::in(I) is also a type, and tag::in is not a macro, how does tag::in(I) give a type at compile-time?

See also http://en.cppreference.com/w/cpp/experimental/ranges/algorithm/copy

like image 417
xmllmx Avatar asked Jun 11 '26 06:06

xmllmx


1 Answers

It is a type of a function accepting I and returning tag::in, which is also a type.

This is used, for example in std::function, like std::function<void(int)>.

like image 185
yuri kilochek Avatar answered Jun 13 '26 20:06

yuri kilochek



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!