dimanche 18 février 2018

Static variable type and dependent class template using nested lambdas

The actual source code is voluminous, so I have phrased this question using syntax similar to psuedo-code, while highlighting the usage context within the actual source code.

The template

template<typename T1, typename T2>
tree{

public:

using type_null_const_sp2node = typename node<T1>::null_const_sp2node;

private:

void reLinkNodes();

};

depends on the template

template<typename T1>
node{

public:

static const std::shared_ptr<node<T1>> null_const_sp2node;

};


template<typename T1> static const node<T1>::null_const_sp2node = NULL;


template<typename T1, typename T2>
void tree<T1,T2>::reLinkNodes(){


   std::function<void(//args)> lambda_fn1 = [&](//args){


    //nested lambda

    std::function<void(//args)> lambda_fn2 = [&](//args){

      //need to use the type D here

     };

     lambda_fn2(//args);
   };

   decltype(type_null_const_sp2node) D;

   lambda_fn1(//args);

}

The issue that I am facing with the above usage is that the type D, as implied and used within lambda_fn2, is not recognised by the compiler. I get the following error messages:

error: use of undeclared identifier 'D'
error: unexpected type name 'type_null_const_sp2node':         
expected expression
  decltype(type_null_const_sp2node) D;

error: no type named 'null_const_sp2Node' in 
'node<std::__1::basic_string<char> >'
using type_null_const_sp2node = typename node<T1>:: 
null_const_sp2Node;

3 errors generated.

My intention is to access the type of the static variable defined in the template node<T1>, inside the nested lambda function object defined inside the reLinkNodes() private method, of the dependent template tree<T1,T2>, for any instantiation of the templates.

What is the correct way of achieving this?

Aucun commentaire:

Enregistrer un commentaire