Skip to main content

Questions tagged [sfinae]

Substitution failure is not an error (SFINAE) refers to a situation in C++ where an invalid substitution of template parameters is not in itself an error. This exploit can be used as a means to implement several template metaprogramming techniques.

Filter by
Sorted by
Tagged with
2 votes
0 answers

Improving constexpr invoke function C++17, alternative to std::invoke

I've learned that in C++17, std::invoke isn't constexpr. To make a constexpr version, I could copy the implementation provided here: , OR I ...
Steve Zhang's user avatar
1 vote
0 answers

Making std::optional a monad via SFINAE

To practice with SFINAE, template meta programming, functional programming and monads in C++, I decided to try writing a skinny version of the two functions (monadic binding and return) that make <...
Enlico's user avatar
  • 537
2 votes
2 answers

Estimate 𝜋 using Machin's formula

Overview Below is a simple program to estimate pi to the full precision of the provided type. It uses Machin's formula, but this question is about coding style / choices. It compares the result to <...
Oliver Schönrock's user avatar
5 votes
1 answer

Using SFINAE to provide "default" output operators

I am an undergraduate CS student trying to implement simple unit test framework on C++ as a pet project. The framework has an assertion macro like ...
pazamelin's user avatar
2 votes
1 answer

type erased pointer to member function callable and SFINAE [closed]

I'm implementing a std::function like class that uses type erasure. So far it can be used with function objects (functions/function pointers, functors, lamdas) and pointer to member function. But to ...
Luca's user avatar
  • 123
5 votes
1 answer

Emulating Virtual Registers Part 3

Forward This is a continuation of my work in progress and the last iteration that I posted can be found here. I have designed a compact class template that uses SFINAE with constructor delegation to ...
Francis Cugler's user avatar
9 votes
1 answer

C++17 is_integral trait implementation

This is a C++17 is_integral trait implementation. Most implementations exhaust all integral types: bool ...
L. F.'s user avatar
  • 9,570
3 votes
1 answer

Implementation of static_vector using an array of std::aligned_storage, with std::launder and forwarding

I'm trying to expand on the implementation of static_vector on the std::aligned_storage reference page, but would like to split it into two parts. First, an ...
rtek's user avatar
  • 53
10 votes
3 answers

`sfinae</* ... */>` proposal... useful or unnecessary?

I am trying to learn what SFINAE is. I believe I understand it quite well; however, I do not have a lot of practice in the subject. I mean I would find it difficult to list all the cases in which <...
PatrykB's user avatar
  • 353
5 votes
0 answers

Using SFINAE with wrappers to terminate compilation early

The Goal Provide some wrappers to a C++11 template library's main entry point so that if the initial template parameter is not valid, the user is informed of exactly what is missing. In the real ...
svenevs's user avatar
  • 205
5 votes
1 answer

Set an order or precedence when calling functions that may or may not exist

In the process of over-engineering a custom library, I implemented expression SFINAE to detect and call specific member functions only if they exist. I also let classes overload these functions and ...
Logan Barnes's user avatar
0 votes
1 answer

SFINAE with several condition [Refactoring] [closed]

How can I write this function shorter? ...
21koizyd's user avatar
  • 217
8 votes
1 answer

C++ template type traits for class members

I have written type traits for checking, if given class T has_member, then if it either ...
xinaiz's user avatar
  • 181
10 votes
3 answers

C++ Vector The basics

Following on from my two previous posts. An alternative vector An Alternative Vector (Copy Assignment Operator) I have written a detailed blog about how to write a minimal vector like class. This ...
Loki Astari's user avatar
  • 95.3k
7 votes
1 answer

A trait class to detect whether a template is specialized for a given type

Today's question will just be about a small utility that I needed at some point for one of my projects: a template to detect whether a template is specialized for a given type. The utility uses ...
Morwenn's user avatar
  • 20k
9 votes
1 answer

Continuation Implementation in C++11

While playing with the concurrency features in C++11 I noticed that there wasn't any support for continuations. I wanted to develop something similar to Tasks in The Parallel Patterns Library (PPL), ...
Eóin Ó'Flynn's user avatar
4 votes
3 answers

Use of macros to aid visual parsing of SFINAE template metaprogramming

I've recently been introduced to SFINAE to solve the problem of unwanted promotion precedence. i.e. I was hoping to catch integer types with Foo::Foo(long) and ...
P i's user avatar
  • 629