Questions,
What do you pass in for the template parameters?
Why do you use const rvalue references when you are trying to use move semantics, and why no std::move or std::forward?
I have tried simple types like int, float and char as three of the parameters, but keep getting error
Error: Type does not exist within the TypeList!
How dangerous is this class exactly?
-
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Re: How dangerous is this class exactly?
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com
- cyboryxmen
- Posts: 190
- Joined: November 14th, 2014, 2:03 am
Re: How dangerous is this class exactly?
That was a mistype. The r-value references were supposed to be non-const.albinopapa wrote: Why do you use const rvalue references when you are trying to use move semantics, and why no std::move or std::forward?
I think you did the same mistake I did where the first template parameter is supposed to be the type used to store the index of the enum. So by typing <int, float, char>, you are making the index an int type and the Room be able to store types of float and char.albinopapa wrote: I have tried simple types like int, float and char as three of the parameters, but keep getting error
Error: Type does not exist within the TypeList!
-Zekilk
Zekilk
-
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Re: How dangerous is this class exactly?
Spinning my wheels, and nothing.
Can you show an example of creating a room from start to finish?
Can you show an example of creating a room from start to finish?
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com
- cyboryxmen
- Posts: 190
- Joined: November 14th, 2014, 2:03 am
Re: How dangerous is this class exactly?
Here is a test I did in main.cpp
-Zekilk
Code: Select all
void main()
{
using Room = shared::Room<std::size_t, int, unsigned, short, char, float, double>;
Room room;
room.CheckIn(int(5));
if (room.GetCurrentOccupant() == Room::EnumClass::IndexOf<double>::index)
{
std::cout << room.Visit<double>() << std::endl;
}
if (room.GetCurrentOccupant() == Room::EnumClass::IndexOf<int>::index)
{
std::cout << room.Visit<int>() << std::endl;
}
room.CheckIn<double, true>(double(12));
if (room.GetCurrentOccupant() == Room::EnumClass::IndexOf<double>::index)
{
std::cout << room.Visit<double>() << std::endl;
}
if (room.GetCurrentOccupant() == Room::EnumClass::IndexOf<int>::index)
{
std::cout << room.Visit<int>() << std::endl;
}
room.CheckIn<float, true>(float(5));
if (room.GetCurrentOccupant() == Room::EnumClass::IndexOf<double>::index)
{
std::cout << room.Visit<double>() << std::endl;
}
if (room.GetCurrentOccupant() == Room::EnumClass::IndexOf<int>::index)
{
std::cout << room.Visit<int>() << std::endl;
}
using List = shared::TypeList<int, unsigned, short, void, char, float, double, void>;
std::cout << "Has Duplicates: " << List::HasDuplicates::value << std::endl;
std::cout << "Has void: " << List::HasVoid::value << std::endl;
std::cout << "Index of void: " << List::IndexOf<void>::index << std::endl;
std::cout << "Index of short: " << List::IndexOf<short>::index << std::endl;
std::cout << "Index of char: " << List::IndexOf<char>::index << std::endl;
std::cout << "Index of int: " << List::IndexOf<int>::index << std::endl;
std::cout << "Index of long: " << List::IndexOf<long>::index << std::endl;
std::cout << "Index of long long: " << List::IndexOf<long long>::index << std::endl;
std::cout << "Index of float: " << List::IndexOf<float>::index << std::endl;
std::cout << "Index of double: " << List::IndexOf<double>::index << std::endl;
std::cout << "Index of long double: " << List::IndexOf<long double>::index << std::endl;
std::cout << "Index of bool: " << List::IndexOf<bool>::index << std::endl;
std::cout << "Index of wchar_t: " << List::IndexOf<wchar_t>::index << std::endl;
std::cout << std::endl;
shared::EnumClass<std::size_t, int, unsigned, short, char, float, double> enum_class1;
shared::EnumClass<std::size_t, float, double, long double> enum_class2;
enum_class1.Set<int>();
enum_class2.Set<float>();
std::cout << "Value of enum: " << enum_class1.GetEnum() << std::endl;
enum_class1 = enum_class2;
std::cout << "Value of enum: " << enum_class1.GetEnum() << std::endl;
system("pause");
}
Zekilk
- cyboryxmen
- Posts: 190
- Joined: November 14th, 2014, 2:03 am
Re: How dangerous is this class exactly?
P.s. Do take note that the typelist in the test here is bugged. This is because the typelist terminates on void so typing void into the list can terminate it prematurely. The typelist automatically adds void to the ends of the list anyway so there is no need to type void in one of its template parameters.
Zekilk
-
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Re: How dangerous is this class exactly?
Wow, a lot of CppCon 2015 was over metaprogramming. Have been watching a few videos on Youtube covering last years CppCon and my brain hurts. I don't think I'll be getting into template metaprogramming...ever lol.
What you have is quite impressive considering the complexity of metaprogramming.
What you have is quite impressive considering the complexity of metaprogramming.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com