Questions tagged [is-same]

is_same is the most common C++ type trait returning a build time expression of type true_type or false_type depending if its 2 template arguments are the same type.

15 questions
4
votes
1 answer

function type when used with decltype

I was looking into decltype and std::is_same_v and tried them on functions. template void func(T t){} template using f = decltype(func); template using ff = decltype((func)); template using…
TheScore
  • 329
  • 3
  • 14
4
votes
1 answer

std::is_same doesn't work through decltype of constexpr auto variable

I was trying to static_assert that some meta transformer algorithm worked, and it incredibly did not compare to same, even though the typeid().name() returned the exact same string. A repetition of the type expression in the typedef could fix the…
v.oddou
  • 6,476
  • 3
  • 32
  • 63
3
votes
1 answer

std::is_same absurd behaviour on type equality check

Consider the following code: struct A { using type = int; using reference = int&; }; static_assert(std::is_same_v); // <-- Success, as it would be static_assert(std::is_same_v); //…
user7769147
  • 1,559
  • 9
  • 15
2
votes
1 answer

Why doesn't decltype(*this)::value_type compile?

Why doesn't decltype(*this) compile? It shows an error message: error: 'value_type' is not a member of 'const Foo&' So what exactly is the reason that decltype( *this )::value_type does not compile in the below program: #include…
digito_evo
  • 3,216
  • 2
  • 14
  • 42
2
votes
1 answer

Compile-Time Type Checking for Recursive Tree Data Structure

Objective: I am implementing a tree data structure which shall make use of recursive interface functions. My tree is composed of nodes and leaf nodes. Nodes are composed of metadata and child nodes, whereas leaf node is an alias for a simple data…
2
votes
1 answer

Google test (gtest) `EXPECT_TRUE()` macro won't compile with `std::is_same<>` template as input

In C++17 with clang compiler, I get the same build errors whether I do this: EXPECT_TRUE(std::is_same_v); or this: EXPECT_TRUE(typename std::is_same_v);, or this: EXPECT_TRUE(typename…
Gabriel Staples
  • 36,492
  • 15
  • 194
  • 265
1
vote
1 answer

C++11 Compare types of two variables or a variable against a type

In summary, I would like to be able to check if the type of an object matches some type or if two objects match types. The essence of what I'm trying to do is pasted below: #include #include #include
Tony A
  • 98
  • 1
  • 6
1
vote
2 answers

std::is_same else static assert

I like to to specialize a function with respect to a template type. This works fine with std::is_same. Now, I like the code to not compile, if a not specialized type is given. template constexpr double get(const T& item) const { if…
schorsch312
  • 5,553
  • 5
  • 28
  • 57
0
votes
0 answers

std::is_same does not work within template

I wanna stringify object in a template class, and I wrote this: template template auto HashTable::Stringify(T key) -> std::string{ if(std::is_same::value){...} else if(std::is_same
Xin_Wang
  • 1
  • 1
0
votes
3 answers

typedef const char* vs. const typedef char*

I have noticed that constness on a typedef'ed pointer loses its ability to be converted implicitly to a const type of the un-typedef'ed type. Since I am clearly lacking proper vocab to explain the issue, I'll show some examples. The following code…
vdavid
  • 2,434
  • 1
  • 14
  • 15
0
votes
0 answers

How to verify inherited type

I'm working in an old code where a pointer of an object of type A is passed to a function: void fun(A* a) { if (dynamic_cast(a) != NULL) { // Use B object } else { // Use C object } } The classes B and C…
Ivan
  • 1,352
  • 2
  • 13
  • 31
0
votes
0 answers

error: request for member ‘..’ in ‘..’, which is of non-class type ‘..’

I started a simple big integer library project, and decided to take it up again. But I can get over this error I am getting. template bigint(T a) { // Constructor for bigint passed // Let's call this 'A' if…
Hardik
  • 1
  • 1
0
votes
1 answer

Is it a day in the current week? Moment JS

I have one problem. Can you tell me how to check does it day in the current week? I am working on some service for a weather forecast. I have a current day but must check does it in the current week. Only what I know is that I must use 'isSame'…
-1
votes
3 answers

Need help writing a function to check if two BSTs have the same structure

I'm trying write a function to check if two trees have the same structure, regardless of values, and the code that I wrote so far doesn't work. Any help or pointers (pun intended) would be greatly appreciated. template bool…
-2
votes
1 answer

Same Template struct, C++

Consider I have structs RGB and ARGB. template struct RGB { T r,g,b; }; template struct ARGB { T a,r,g,b; } Now I define them by following. using RGB_888 = RGB; using RGB_Float = RGB; using…
Hrant Nurijanyan
  • 789
  • 2
  • 9
  • 26