Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
libnest2d::opt::metaloop Class Reference

Helper class to be able to loop over a parameter pack's elements. More...

#include <src/libnest2d/include/libnest2d/utils/metaloop.hpp>

Classes

class  _MetaLoop
 
class  _MetaLoop< Int< 0 >, Args... >
 
class  _MetaLoop< Int< N >, Args... >
 
class  MapFn
 

Static Public Member Functions

template<class... Args, class Fn >
static void apply (Fn &&fn, Args &&...args)
 The final usable function template.
 
template<class... Args, class Fn >
static void apply (Fn &&fn, tuple< Args... > &&tup)
 The version of apply with a tuple rvalue reference.
 
template<class... Args, class Fn >
static void apply (Fn &&fn, tuple< Args... > &tup)
 The version of apply with a tuple lvalue reference.
 
template<class... Args, class Fn >
static void apply (Fn &&fn, const tuple< Args... > &tup)
 The version of apply with a tuple const reference.
 
template<class Fn , class Tup , std::size_t... Is>
static auto callFunWithTuple (Fn &&fn, Tup &&tup, index_sequence< Is... >) -> decltype(fn(std::get< Is >(tup)...))
 

Private Types

template<int N>
using Int = std::integral_constant< int, N >
 
template<class... Args>
using MetaLoop = _MetaLoop< Int< sizeof...(Args) -1 >, Args... >
 

Detailed Description

Helper class to be able to loop over a parameter pack's elements.


Class Documentation

◆ libnest2d::opt::metaloop::_MetaLoop

class libnest2d::opt::metaloop::_MetaLoop
template<typename Idx, class... Args>
class libnest2d::opt::metaloop::_MetaLoop< Idx, Args >

Member Typedef Documentation

◆ Int

template<int N>
using libnest2d::opt::metaloop::Int = std::integral_constant<int, N>
private

◆ MetaLoop

template<class... Args>
using libnest2d::opt::metaloop::MetaLoop = _MetaLoop<Int<sizeof...(Args)-1>, Args...>
private

Member Function Documentation

◆ apply() [1/4]

template<class... Args, class Fn >
static void libnest2d::opt::metaloop::apply ( Fn &&  fn,
Args &&...  args 
)
inlinestatic

The final usable function template.

This is similar to what varags was on C but in compile time C++11. You can call: apply(<the mapping function>, <arbitrary number of arguments of any type>); For example:

 struct mapfunc {
     template<class T> void operator()(int N, T&& element) {
         std::cout << "The value of the parameter "<< N <<": "
                   << element << std::endl;
     }
 };

 apply(mapfunc(), 'a', 10, 151.545);

C++14: apply([](int N, auto&& element){ std::cout << "The value of the parameter "<< N <<": " << element << std::endl; }, 'a', 10, 151.545);

This yields the output: The value of the parameter 0: a The value of the parameter 1: 10 The value of the parameter 2: 151.545

As an addition, the function can be called with a tuple as the second parameter holding the arguments instead of a parameter pack.

189 {
190 MetaLoop<Args...>().run(tuple<Args&&...>(forward<Args>(args)...),
191 forward<Fn>(fn));
192}
_MetaLoop< Int< sizeof...(Args) -1 >, Args... > MetaLoop
Definition metaloop.hpp:152

Referenced by libnest2d::opt::NloptOptimizer::optfunc(), and libnest2d::opt::NloptOptimizer::optimize().

+ Here is the caller graph for this function:

◆ apply() [2/4]

template<class... Args, class Fn >
static void libnest2d::opt::metaloop::apply ( Fn &&  fn,
const tuple< Args... > &  tup 
)
inlinestatic

The version of apply with a tuple const reference.

208 {
209 MetaLoop<Args...>().run(tup, forward<Fn>(fn));
210}

◆ apply() [3/4]

template<class... Args, class Fn >
static void libnest2d::opt::metaloop::apply ( Fn &&  fn,
tuple< Args... > &&  tup 
)
inlinestatic

The version of apply with a tuple rvalue reference.

196 {
197 MetaLoop<Args...>().run(std::move(tup), forward<Fn>(fn));
198}

◆ apply() [4/4]

template<class... Args, class Fn >
static void libnest2d::opt::metaloop::apply ( Fn &&  fn,
tuple< Args... > &  tup 
)
inlinestatic

The version of apply with a tuple lvalue reference.

202 {
203 MetaLoop<Args...>().run(tup, forward<Fn>(fn));
204}

◆ callFunWithTuple()

template<class Fn , class Tup , std::size_t... Is>
static auto libnest2d::opt::metaloop::callFunWithTuple ( Fn &&  fn,
Tup &&  tup,
index_sequence< Is... >   
) -> decltype(fn(std::get<Is>(tup)...))
inlinestatic

Call a function with its arguments encapsualted in a tuple.

219{
220 return fn(std::get<Is>(tup)...);
221}

Referenced by libnest2d::opt::NloptOptimizer::optfunc().

+ Here is the caller graph for this function:

The documentation for this class was generated from the following file: