I am trying to write my own implementation of the tuple_size function before looking how it is implemented in C++ library. The problem that I am getting right now is that I am getting wrong answer (1) and I do not see any preconditions for that. Appreciate any help.
#include <iostream>
using namespace std;
namespace tuple_helpers
{
template <typename... Args>
struct _tuple_size;
template<typename T, typename... Args>
class _tuple_size<T, Args...>
{
public:
constexpr static size_t __size()
{
return _tuple_size<Args...>::__size() + 1;
}
};
template<>
class _tuple_size<>
{
public:
constexpr static size_t __size()
{
return 0;
}
};
template<typename T>
class tuple_size
{
public:
enum { value = _tuple_size<T>::__size() };
};
}
int main()
{
using MyTuple = tuple<int, string, bool, double>;
cout << "Size of the tuple is: " << tuple_helpers::tuple_size<MyTuple>::value;
return 0;
}