Skip to main content
The 2024 Developer Survey results are live! See the results

Questions tagged [type-traits]

Type traits are syntactic extensions that allow the developer to determine at compile time various characteristics of a type. C++ support is provided by a combination of compiler support and a set of library templates. Access to the type traits is provided via the header <type_traits>

0 votes
3 answers
64 views

how to create a template with both default type argument and variadic type argument? or any work around

I created a trait struct FnOnArg to see if Fn can call on Arg template<typename Fn, typename Arg, typename=void> struct FnOnArg: std::false_type {}; template<typename Fn, typename Arg> ...
hczstev's user avatar
  • 45
-1 votes
1 answer
64 views

std::is_same_v weirdly return false when true is expected using CRT pattern

#include <iostream> #include <type_traits> template <template <typename,unsigned,typename...>typename interface,typename T,unsigned ChannelN, typename...Args> struct base : ...
Dong's user avatar
  • 31
2 votes
1 answer
125 views

Why does this static_assert on a pointer to an incomplete type in a templated function apparently work?

In the process of replacing a static_assert in a templated function with a requires statement, we discovered that firstly, the function was occasionally being used on an incomplete type, and that ...
James Picone's user avatar
  • 1,591
0 votes
1 answer
73 views

Why are trait objects usually used via references (&dyn Trait) or smart Pointers (like Box<dyn Trait>)?

In Rust, why are trait objects usually used via references (&dyn Trait) or smart Pointers (like Box<dyn Trait>)? Does it have to be? Or is it better to use it this way?
sundegan's user avatar
2 votes
2 answers
90 views

Why does `std::integral_constant` have a `::type` that refers to itself?

I'm reading the documentation on std::integral_constant, and apparently it includes using type that refers to itself. template <typename T, T Value> struct integral_constant { using type = ...
HolyBlackCat's user avatar
  • 91.2k
-2 votes
2 answers
127 views

How to check whether a function template exists in C++?

Is there a way to check the existence of a function (of a specific signature) regardless of whether it is templated or not? For example: template <bool FLAG> class A { public: template <...
zhanginou's user avatar
  • 185
1 vote
2 answers
115 views

Conditionally declare a variable of a certain type

Here is what I want to achieve: struct A { A(/* ... */) {} A(A const&) = delete; }; struct B { B(/* ... */) {} B(B const&) = delete; }; int main() { static bool constexpr cond = false; ...
0xbadf00d's user avatar
  • 18k
2 votes
1 answer
102 views

How does 'std::add_const' work when I instantiate it with 'const int'? [duplicate]

The following code snippet comes from libstdc++'s implementation of std::add_const, /// add_const template<typename _Tp> struct add_const { typedef _Tp const type; }; If I use int to ...
Meng San-Hu's user avatar
0 votes
3 answers
89 views

How to get the class type of an unnamed struct in a typedef inside the unnamed class?

This is a theoritcal question whether it is possible to get the type of the unnamed struct inside its definition. int main() { struct { using ThisType = ???? //what do i put here? } _;...
user24551355's user avatar
0 votes
0 answers
84 views

Trait for a callable class and signature of operator()

Let's say I have a class template <class T, class Function> class Integration { public: T operator()(const Function & f, T a, T b) const { /// computes the integral of f over ...
11house's user avatar
  • 147
2 votes
1 answer
81 views

SFINAE for checking the validity of a complex expression involving copy assignment

Consider the following classes and take specific note of Concrete<T>::copy_assign: struct TypeErased { TypeErased() = default; TypeErased& operator=(TypeErased const& other) { ...
joergbrech's user avatar
  • 2,742
3 votes
4 answers
151 views

Template specialization using a variable argument

I am trying to wrap a c-style variant in a library. It uses a type enum, which I mean to fill using templates. A simplified version looks roughly like this: enum Type { Type_Int, Type_Double, ...
David van rijn's user avatar
6 votes
1 answer
133 views

How to generalize a template specialization for any variadic template type?

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 T, ...
Ton van den Heuvel's user avatar
0 votes
1 answer
53 views

Is there a way to implement std::regular_invocable as a type_trait style function in c++11/c++14?

I'm currently working on an Arduino "gameboy" style project where I'm trying to make a library that will work like a game engine. In the Arduino IDE there is no c++ STL when using an AVR ...
Andrey Stroitelev's user avatar
2 votes
1 answer
136 views

What was the problem with std::is_callable?

Since 2017-03-13 std::is_callable is gone from cppreference.com. The last available description of it is from 2016-11-21 on WaybackMachine. The main difference between std::is_callable and std::...
Dr. Gut's user avatar
  • 2,723

15 30 50 per page
1
2 3 4 5
85