Celeritas  0.5.0-86+4a8eea4
Functions
Join.hh File Reference
#include "detail/Joined.hh"
This graph shows which files directly or indirectly include this file:

Functions

template<class InputIterator , class Conjunction >
detail::Joined< InputIterator, Conjunction, detail::StreamValue > celeritas::join (InputIterator first, InputIterator last, Conjunction &&conjunction)
 Join items, similar to python's "str.join" method. More...
 
template<class InputIterator , class Conjunction , class UnaryOperation >
detail::Joined< InputIterator, Conjunction, detail::UnaryToStream< UnaryOperation > > celeritas::join (InputIterator first, InputIterator last, Conjunction &&conjunction, UnaryOperation &&op)
 Join items transformed by a helper functor. More...
 
template<class InputIterator , class Conjunction , class StreamOp >
detail::Joined< InputIterator, Conjunction, StreamOp > celeritas::join_stream (InputIterator first, InputIterator last, Conjunction &&conjunction, StreamOp &&op)
 Join using a functor that takes (ostream&, value).
 

Function Documentation

◆ join() [1/2]

template<class InputIterator , class Conjunction >
detail::Joined<InputIterator, Conjunction, detail::StreamValue> celeritas::join ( InputIterator  first,
InputIterator  last,
Conjunction &&  conjunction 
)

Join items, similar to python's "str.join" method.

This utility function will concatenate the values passed to it. The given conjunction ONLY appears between values.

cout << celeritas::join(foo.begin(), foo.end(), ", ") << endl
detail::Joined< InputIterator, Conjunction, detail::StreamValue > join(InputIterator first, InputIterator last, Conjunction &&conjunction)
Join items, similar to python's "str.join" method.
Definition: Join.hh:32

The result is a thin class that is streamable. (It can explicitly be converted to a string with the to_string method). By doing this instead of returning a std::string, large and dynamic containers can be e.g. saved to disk.

◆ join() [2/2]

template<class InputIterator , class Conjunction , class UnaryOperation >
detail::Joined<InputIterator, Conjunction, detail::UnaryToStream<UnaryOperation> > celeritas::join ( InputIterator  first,
InputIterator  last,
Conjunction &&  conjunction,
UnaryOperation &&  op 
)

Join items transformed by a helper functor.

This joins all given elements, inserting conjunction betwen them. The 'op' operator must transform each element into a printable object. For example,

[](const std::pair<int, int>& item) { return item->first; }

could be used to get the 'key' item of a map.