0

Trying to make below code to use the etl library.ETL

#include <functional>
#include <tuple>


template < typename Function, typename...Args >
  class Class {
    private:
      Function function_; //  ---> using etl::delegate
    std::tuple < Args... > args; // ?????
    public:
      Class(Function _function, Args..._args):
      function_ {std::forward < Function > (_function }, // ----> using etl::forward
      args {std::forward < Args > (_args)... }
        {}
    
        auto function()
        {
            return std::apply(function_,args); // ????
        }
    };
  1. std::tuple , std::make_tuple To store parameters --> etl::variant ( etl::variant )

Most of the examples have an std::make_tuple which I couldn't find an etl equvialnet. Is there any other option beside using etl::variant?

etl::variant<Args...> args;
public:
    Class(Function _function, Args... _args) :  
        function_ { etl::forward<Function>(_function) } ,
        args{/*std::make_tuple*/
      < etl::forward < Args > (_args)... >
  } // is make_tuple a must??
{}
  1. std::apply To unpack and invoke. I used code another implementaion, using an index sequencer. But replacing std::tuple with etl::variant throws an error.;
template <typename... Args, int... Is>
void func(etl::variant < Args... > & tup, helper::index < Is... > ) {
  f(std::get < Is > (tup)...);
}

template < typename...Args, int...Is >
  void func(etl::variant < Args... > & tup, helper::index < Is... > ) {
    f(std::get < Is > (tup)...);
  }
template < typename...Args >
  void func(etl::variant < Args... > & tup) {
    func(tup, helper::gen_seq < sizeof...(Args) > {}); // this shows an error and won't run.
  }
Dima S
  • 1
  • 5
  • 2
    A `tuple` and a `variant` are completely different things. You can't replace one with the other. If the library doesn't have a `tuple` type and you can't use `std::tuple` or a `tuple` implementation from another library, then you will just have to implement one yourself. – user17732522 Aug 25 '22 at 11:05
  • I think the etl:: library is already using something similar to tuple, just can't figure out how – Dima S Aug 25 '22 at 11:13
  • 1
    From [a github issue](https://github.com/ETLCPP/etl/issues/440) asking about an `etl::tuple`: "_The original intention for the ETL was to complement the STL, not replace it,_ [...]". Also the library author is mentioning that he might not have the time/resources to add re-implementations of all of these `std` features. So the answers seems to be: Just use `std::tuple`. – user17732522 Aug 25 '22 at 11:17
  • locked out of any std:: functionality for safety – Dima S Aug 25 '22 at 11:34
  • Then you are probably going to have to re-implement `std::tuple` and its facilities yourself or find another library that is acceptable according to your policies. I am btw. not sure how using the `etl` library would be less of a safety concern than using the `std` variants. It is very likely that the latter is much better tested and verified. `std::tuple` implementations also don't make use of anything potentially problematic like dynamic allocations or exceptions, which is also probably why the ETL author didn't give that priority as a feature for his library. – user17732522 Aug 25 '22 at 12:00

0 Answers0