hpx/pack_traversal/pack_traversal.hpp#

Defined in header hpx/pack_traversal/pack_traversal.hpp.

See Public API for a list of names and headers that are part of the public HPX API.

namespace hpx
namespace util

Functions

template<typename Mapper, typename... T> < unspecified > map_pack (Mapper &&mapper, T &&... pack)

Maps the pack with the given mapper.

This function tries to visit all plain elements which may be wrapped in:

  • homogeneous containers (std::vector, std::list)

  • heterogeneous containers (hpx::tuple, std::pair, std::array) and re-assembles the pack with the result of the mapper. Mapping from one type to a different one is supported.

Elements that aren’t accepted by the mapper are routed through and preserved through the hierarchy.

// Maps all integers to floats
map_pack([](int value) {
    return float(value);
},
1, hpx::make_tuple(2, std::vector<int>{3, 4}), 5);

Throws

std::exception – like objects which are thrown by an invocation to the mapper.

Parameters
  • mapper – A callable object, which accept an arbitrary type and maps it to another type or the same one.

  • pack – An arbitrary variadic pack which may contain any type.

Returns

The mapped element or in case the pack contains multiple elements, the pack is wrapped into a hpx::tuple.