type-traits Questions

3

Solved

I'm trying to return an int64_t if std::is_integral<>::value is true. Otherwise, I would like to call to_int64t() on the object. My attempt below is failing because partial specialisation o...
Angeli asked 24/3, 2013 at 13:19

2

Solved

I'd like to use std::is_invocable, but it is available only since C++17, and we are using C++11 Standard. Is there any way to emulate the functionality using C++11?
Convex asked 5/7, 2018 at 9:36

4

Solved

I'm trying to declare a variable so that its type is the same as the return type of a member function to which I have a member function pointer. class Widget { public: std::chrono::milliseconds ...
Argumentum asked 21/3, 2015 at 16:15

2

So I'm trying to make a type trait that says whether two "outer" class types are the same. ie. std::vector<int> is the same as std::vector<double>, I don't care about any inner argumen...

1

Solved

I have the following type function to calculate whether some type T is part of the list of types in an std::tuple: template<typename T, typename Tuple> struct IsInTuple; template<typename...
Kryska asked 4/4, 2024 at 8:55

5

Solved

Consider the following code: #include <iostream> #include <type_traits> int main() { std::cout << "std::is_same<int, int>::value = " << std::is_same<i...
Scarify asked 12/5, 2013 at 1:38

2

Solved

I am trying to update some older code to the coming C++20 language using current GCC10. I was not able to update some templates because they used a std::enable_if<std::is_enum_v<T>> co...
Heshum asked 18/5, 2020 at 17:8

8

Solved

I'm trying to figure out how to write a conecpt that checks that there are no repeated types in a variadic template. I'm aware I can't call a concept recursively within itself, but if I could my so...
Queston asked 6/4, 2023 at 12:1

4

Solved

While playing around with compile-time string (variadic lists of char) manipulation, I needed to implement a way of checking if a compile-time string contained another (smaller) compile-time string...
Belletrist asked 10/2, 2015 at 13:32

10

Solved

In my function template, I'm trying to check whether the type T is a specific type. How would I do that? template<class T> int foo(T a) { // check if T of type, say, String? }
Backgammon asked 15/2, 2010 at 10:54

5

I have a number of places in which I wish to use std::enable_if to allow certain templates only if a simple static cast from template type A to template type B (both of which are numeric) will not ...
Hekate asked 28/3, 2016 at 20:1

4

Solved

There are a lot of *_v and *_t suffixes, like std::is_same_v, std::invoke_result_t, result_of_t and milions of other such functions. Why do they exist at all? Is it beneficial in any context to exp...
Rood asked 11/9, 2023 at 17:32

3

Solved

I have a problem in my application where I'd like to assert that a function application would be rejected by the compiler. Is there a way to check this with SFINAE? For example, assume that I'd li...
Cartwright asked 5/5, 2012 at 0:39

4

Solved

In C++, it is possible to use std::is_same to check if two types are exactly identical. Is there a way to check if two types are identical except, maybe, a const or a & modifier? Here is an exa...
Sis asked 16/5, 2019 at 1:45

5

Is there a way (trait or so) to detect, if struct/class has some padding? I don't need cross-platform or standardized solution, I need it for MSVC2013. I can check it like namespace A { struct...
Trixi asked 14/8, 2015 at 9:50

3

Solved

This is from: https://github.com/gcc-mirror/gcc/blob/master/libstdc++-v3/include/std/type_traits template<typename _Xp, typename _Yp> using __cond_res = decltype(false ? declval<_Xp(&am...
Liken asked 26/6, 2023 at 17:51

2

Solved

I have a type trait and concept which checks if an std::variant can hold a given type T. Now I have a type variant2 which derives from std::variant, and I want to use that type trait with the new v...
Kayne asked 12/6, 2023 at 14:47

2

Related but much more arcane than C++11 static assert for equality comparable type? — JF Bastien's paper N4130 "Pad Thy Atomics!" got me thinking that if we're going to use atomic<T>::compar...
Supercool asked 10/12, 2017 at 18:34

2

Solved

Working on a real-life project, I've stumbled across the weird behavior of some (versions of some) compilers. Consider the following class declaration(s): struct OptionalsStruct { struct InnerType...
Joycejoycelin asked 22/3, 2023 at 16:38

2

Solved

I have a long series of if constexpr statements and would like to trigger a compile-time error if none of them succeed. Specifically, I have an abstract syntax tree whose result I would like to con...
That asked 8/10, 2021 at 20:37

5

Solved

I have a class whose behavior I am trying to configure. template<int ModeT, bool IsAsync, bool IsReentrant> ServerTraits; Then later on I have my server object itself: template<typename T...
Hypercorrect asked 5/2, 2013 at 22:16

3

Solved

Is it possible to determine how many variable names should I to specify in square brackets using structured bindings syntax to match the number of data members of a plain right hand side struct? I...

3

Solved

Should the type trait be able to handle cases such as std::vector < std::unique_ptr <int> > and detect that it's not copy constructible? Here's an example at https://ideone.com/gbcRUa...
Unwelcome asked 23/8, 2013 at 13:29

2

So I've just started off with Google's OpenFST toolkit and I'm trying out their examples. Using C++ on Eclipse Mars and upon build I get the following error: fatal error: 'type_traits' file not fo...
Darwindarwinian asked 5/1, 2017 at 6:9

4

Solved

Consider this example: #include <iostream> #include <type_traits> template <class, class = void> struct is_defined : std::false_type { }; template <class T> struct is_def...
Ingrained asked 2/10, 2016 at 12:0

© 2022 - 2025 — McMap. All rights reserved.