I have following code:
class TR_AgentInfo : public tuple<
long long, //AgentId
string, //AgentIp
>
{
public:
TR_AgentInfo() {}
TR_AgentInfo(
const long long& AgentId,
const string& AgentIp,
)
{
get<0>(*this) = AgentId;
get<1>(*this) = AgentIp;
}
long long getAgentId() const { return get<0>(*this); }
void setAgentId(const long long& AgentId) { get<0>(*this) = AgentId; }
string getAgentIp() const { return get<1>(*this); }
void setAgentIp(const string& AgentIp) { get<1>(*this) = AgentIp; }
};
Now I want to use this code:
int count = tuple_size<TR_AgentInfo>::value;
but gcc give this error:
error: incomplete type std::tuple_size<TR_AgentInfo> used in nested name specifier
now what can I do ?
If you just want your one class to work with
std::tuple_size, you can simply provide a specialization:You are expressly allowed to add specializations to the namespace
std, precisely for situations like yours.If your actual class is itself templated, you can simply replace
2by an appropriate construction. For example, for suggestion #1 you could add a typedef fortuple_typeto your class. There are many ways to skin this cat.