i am tryng to implement a range selector,using template metaprogramming for de range unit ; but i am getting stuck with a compile time error. I now that an error like undefinned reference is because the linker it not seeing a variable, so eventually a move that variable to an namespace , it first create and then it resolve the conflict. but in this case, i cannot do that , i need that tuple definned in that order, initialized by templates arguments. Here is the code:
#include <iostream>
#include <tuple>
namespace NSIndexSelector
{
namespace variables
{
}
template<typename OutPutValueType,typename IndexValueType,const IndexValueType BEGIN_VALUE, const IndexValueType END_VALUE,unsigned RANGE_INDEX>
class RangeUnit
{
static constexpr unsigned NOT_IN_RANGE=100;
static constexpr std::tuple<IndexValueType,IndexValueType> tuplaRange{BEGIN_VALUE,END_VALUE};
public:
RangeUnit()
{}
static bool isInRange(const IndexValueType aIndexValue, unsigned & aIndexRange)
{
bool result=false;
std::get<static_cast<unsigned>(TupleIndex::First)>(tuplaRange);
//result=((std::get<TupleIndex::First>(tuplaRange))<aIndexValue && aIndexValue<(std::get<TupleIndex::First>(tuplaRange)));
aIndexRange=(result?RANGE_INDEX:NOT_IN_RANGE);
return result;
}
private:
enum class TupleIndex
{
First,
Last
};
};
}
int main()
{
static constexpr unsigned InitialValue=0;
static constexpr unsigned LastValue=10;
static constexpr unsigned RANGE_INDEX=1;
NSIndexSelector::RangeUnit<unsigned,unsigned,InitialValue,LastValue,RANGE_INDEX> RangeUnit;
unsigned aRangeValue=0U;
unsigned aIndexValue=11;
NSIndexSelector::RangeUnit<unsigned,unsigned,InitialValue,LastValue,RANGE_INDEX>::isInRange(aIndexValue,aRangeValue);
return 0;
}
I am a little bit tired by this hours, and i cannot see where is the error. Thx in advance,! Question: I have an undefinned refence to std::tuple<> ..., but how do i initialize the variable before it is called?, i have already try to init outside the class.
Aucun commentaire:
Enregistrer un commentaire