Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

ref_unwrapped
PrevUpHomeNext

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.

  • Precondition: The value_type of the range has a .get() const.
  • Postcondition: For all elements x in the returned range, x is the result of y.get() where y is the corresponding element in the original range.
  • Range Category: Single Pass Range
  • Range Return Type: boost::unwrap_ref_range<decltype(rng)>
  • Returned Range Category: The range category of rng.

#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