cppx-core
Macros
macro-items_of.hpp File Reference

$items_of eases use of standard library functions, e.g. sort( $items_of( numbers ) ). More...

#include <cppx-core/meta-macro/only_lvalue_ref_to.hpp>
#include <iterator>
Include dependency graph for macro-items_of.hpp:

Go to the source code of this file.

Macros

#define items_of   CPPX_ITEMS_OF
 Real name: $items_of (the $ is just removed by Doxygen). More...
 
#define CPPX_ITEMS_OF(c)   std::begin( cppx::only_lvalue_ref_to( c ) ), std::end( c )
 $items_of(c) effectively expands to std::begin(c), std::end(c). More...
 

Detailed Description

$items_of eases use of standard library functions, e.g. sort( $items_of( numbers ) ).

Definition in file macro-items_of.hpp.

Macro Definition Documentation

◆ CPPX_ITEMS_OF

#define CPPX_ITEMS_OF (   c)    std::begin( cppx::only_lvalue_ref_to( c ) ), std::end( c )

$items_of(c) effectively expands to std::begin(c), std::end(c).

$items_of eases use of standard library functions in C++ versions before C++20, e.g. std::sort( $items_of( my_numbers ) ).

There is a check that c is not an rvalue expression, where the expansion could inadvertently duplicate a costly or impure function call. But still, be careful. Don't call this macro with an lvalue expression that has side effects.

Definition at line 23 of file macro-items_of.hpp.

◆ items_of

#define items_of   CPPX_ITEMS_OF

Real name: $items_of (the $ is just removed by Doxygen).

Definition at line 11 of file macro-items_of.hpp.