Witam.
Czy jest możliwe stworzenie funkcji do której można przekazać bool
lub std::vector<bool>
?
Do funkcji przekazuję std::vector<Color*>
oraz dwa std::vector<bool>
, dosyć często zdarza się że dwa następne std::vector<bool>
są w pełni wypełnione tą samą wartością, więc zamiast wywoływania funkcji w ten sposób:
int Result = Color::Check_And_Search_Colors_With_Time({ &Main_Data.Colors[1], &Main_Data.Colors[2] }, { false, false}, {true, true}, Position, 20, 750);
wolałbym wywołać ją w ten sposób:
int Result = Color::Check_And_Search_Colors_With_Time({ &Main_Data.Colors[1], &Main_Data.Colors[2] }, false, true, Position, 20, 750);
Próbowałem stworzyć potrzebną funkcję w poniższy sposób, jednak otrzymuję błąd przy każdym jej wywołaniu:
template <class T> bool Is_Type_Bool(const T& Type)
{
return typeid(T) == typeid(bool);
}
template <class T> void Check(const T& Arg)
{
bool Is_Arg_Bool = Is_Type_Bool(Arg);
bool Arg_Value = Is_Arg_Bool ? Arg : Arg[0];
}
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE P, LPSTR CMD, int nShowCmd)
{
bool A = true;
Check(A);
Check<std::vector<bool>>({ true });
return 0;
}
Error C2109 subscript requires array or pointer type 36
Error C2446 ':': no conversion from 'std::vector<bool,std::allocator<_Ty>>::const_reference' to 'const std::vector<bool,std::allocator<_Ty>>' 36
EDIT: Innym sposobem jest przekazanie do funkcji std::vector
z tylko jednym elementem, rozwiązuje to problem, jednak jestem ciekawy czy można ten problem rozwiązać w lepszy sposób.