Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext
ref_unwrapped
ref_unwrapped example

Syntax

Code

Pipe

rng | boost::adaptors::ref_unwrapped

Function

boost::adaptors::ref_unwrap(rng)

This adaptor produces a range than applies .get() on all values in the range. It is useful for iterating ranges of std::reference_wrapper values or values using similar semantics.

The adaptor is C++11 (and above) only.

#include <boost/range/adaptor/ref_unwrapped.hpp>
#include <iostream>
#include <vector>

struct example
{
  int value;
};

int main(int argc, const char* argv[])
{
    using boost::adaptors::ref_unwrapped;

    example one{1};
    example two{2};
    example three{3};

    std::vector<std::reference_wrapper<example> > input{one, two, three};

    for (auto&& entry : input | ref_unwrapped)
    {
      std::cout << entry.value;
    }

    return 0;
}

This would produce the output 123.


PrevUpHomeNext