enable-if Questions
4
Solved
Is there a way to identify whether or not a base class is a virtual base class?
std::is_base_of will identify a base class, but I'm looking for something like std::is_virtual_base_of to identify a...
3
Solved
Whats wrong with this:
#include <type_traits>
struct A;
template<typename T>
struct B
{
template<typename=std::enable_if<std::is_copy_constructible<T>::value>>
vo...
Kabob asked 10/10, 2019 at 10:5
5
Solved
I have the following case that works using std::enable_if :
template<typename T,
typename std::enable_if<std::is_same<int, T>::value>::type* = nullptr>
void f() { }
template&l...
2
I am learning some modern C++20 features. One of them is concept. I have read https://en.cppreference.com/w/cpp/language/constraints and https://www.modernescpp.com/index.php/defintion-of-concepts ...
5
Solved
Scott Meyers posted content and status of his next book EC++11.
He wrote that one item in the book could be "Avoid std::enable_if in function signatures".
std::enable_if can be used as a function ...
9
Solved
I am trying to get a simple example to work to understand how to use std::enable_if. After I read this answer, I thought it shouldn't be too hard to come up with a simple example. I want to use std...
2
C++20 has landed, bringing with it Concepts. If a project were to start now and target only C++20 and later standards, would it be appropriate to say previous forms of constraints are now supersede...
Elysian asked 27/5, 2023 at 8:51
3
Solved
The minimal example is rather short:
#include <iostream>
#include <array>
#include <type_traits>
struct Foo{
//template <class C>
//Foo(C col, typename std::enable_...
1
Solved
I'm trying to make a function template that takes a function template as a template argument and then returns the result of that function when invoked with the normal function parameters passed in....
5
I would like to conditionally declare a local variable in a function, based on a template bool parameter. So if it is true it should be there, otherwise shouldn't be there in the sense that I don't...
Surreptitious asked 7/12, 2021 at 9:21
11
Is it possible to write a type trait whose value is true for all common STL structures (e.g., vector, set, map, ...)?
To get started, I'd like to write a type trait that is true for a vector and f...
2
Solved
If I have
template <typename T> struct A;
template <typename T> struct B;
template <typename T> struct C;
template <typename T> struct D;
what is the most compact way of te...
Bitartrate asked 1/3, 2021 at 12:34
6
Solved
I am trying to determine which version of a member function gets called based on the class template parameter. I have tried this:
#include <iostream>
#include <type_traits>
temp...
1
Solved
I want to use SFINAE to create a templated member function which takes a Consumer functor. Whether something is a consumer depends on a templated static constexpr bool isConsumer member variable. I...
4
Solved
Given this template:
template <class A>
struct Something {
... // members common to all template instantiations for all A types
SpecialType member; // but not this - I want this to be con...
Agnostic asked 13/4, 2012 at 11:48
4
Solved
C++-14 introduced std::enable_if_t.
What is the difference between it and std::enable_if? Are there any advantages or differences in using std::enable_if_t?
3
Solved
I want to get rid of all the unholy enable_ifs in my templates and replace them with C++20 concepts, however there's barely any info on concepts and the syntax changes with just about any source I ...
Juncaceous asked 14/5, 2020 at 9:19
8
I was thinking of a class like:
template < typename ...Whatever >
class MyClass
{
public:
static constexpr bool has_default_ctr = Something;
// I want this only if "has_default_ctr" is "t...
Update asked 25/4, 2012 at 4:54
5
Solved
In template meta programming, one can use SFINAE on the return type to choose a certain template member function, i.e.
template<int N> struct A {
int sum() const noexcept
{ return _s...
Jethro asked 30/1, 2013 at 11:41
1
Solved
I was reading std::enable_if, and noticed the following.
template <typename Integer,
std::enable_if_t<std::is_integral<Integer>::value, int> = 0
>
T(Integer) : m_type(int_t) {}
...
2
Solved
#include <stdio.h>
#include <type_traits>
void print()
{
printf("cheers from print !\n");
}
class A
{
public:
void print()
{
printf("cheers from A !");
}
};
template<typen...
Onslaught asked 17/2, 2020 at 20:14
2
Solved
I am using function SFINAE heavily in a project and am not sure if there are any differences between the following two approaches (other than style):
#include <cstdlib>
#include <ty...
3
Solved
Consider following code:
#include <iostream>
#include <type_traits>
template <typename T>
struct A {
int val = 0;
template <class = typename std::enable_if<T::val...
Meningitis asked 24/7, 2013 at 18:51
1
Solved
What is the differences between these classes? Specifically, these member functions with enable_if.
/// Alias of std::enable_if...
template <bool B, typename T = void>
using Enable_if = typen...
2
Solved
#include <type_traits>
class Base {
public:
virtual bool f() {
return true;
}
};
template<typename T>
class Derived : public Base {
std::enable_if_t< std::is_copy_constructible...
Ojeda asked 4/8, 2019 at 9:31
1 Next >
© 2022 - 2024 — McMap. All rights reserved.