xmllmx xmllmx -4 years ago 49
C++ Question

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

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

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

Answer Source

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)>.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download