C++ Weekly - Ep 194 - From SFINAE To Concepts With C++20

preview_player
Показать описание
☟☟ Awesome T-Shirts! Sponsors! Books! ☟☟

T-SHIRTS AVAILABLE!

WANT MORE JASON?

SUPPORT THE CHANNEL

GET INVOLVED

JASON'S BOOKS

► C++23 Best Practices

► C++ Best Practices

JASON'S PUZZLE BOOKS

► Object Lifetime Puzzlers Book 1

► Object Lifetime Puzzlers Book 2

► Object Lifetime Puzzlers Book 3

► Copy and Reference Puzzlers Book 1

► Copy and Reference Puzzlers Book 2

► Copy and Reference Puzzlers Book 3

► OpCode Puzzlers Book 1


RECOMMENDED BOOKS

AWESOME PROJECTS

O'Reilly VIDEOS

Рекомендации по теме
Комментарии
Автор

I got pretty used to SFINAE, but damn, I won't miss it when it's gone!

notthedroidsyourelookingfo
Автор

A great, easy-to-follow intro to a concept (NPI) as always Jason. Thanks!

gustafbstrom
Автор

Just wanted to point out that if you check the "Wrap lines" checkbox, then you won't have to scroll right to see the full compiler output.

nbulous
Автор

Add more complexity to make something else simpler. C++ 2019


Please moar concepts!

tiloiam
Автор

I would expect customise error message, as for assert

divad
Автор

This is awesome. As someone who really doesn't like just using auto everywhere because of type obscuring, I can't wait to be able to code in this style.

codyheiner
Автор

But if we replace returned "floating_point auto" with just int, we somehow require the returned value to be int. Although, in this case implicit casts are possible which is, I assume, you didn't want to discuss (probably doesn't make sense in this context as we don't want to have them at all).

davithov
Автор

Hello Json. I really like your videos, they help me alot. May i request a video about std::to_chars floating point that msvc recently implemented in <charconv> header ( C++17) . It kinda weird and i don't know how to use it well. Thank you, i appreciate your knowledges.

tsunekakou
Автор

Hello Jason. Thanks for sharing your knowledges and skills. I appreciate that #cpp #cplusplus

danielphd
Автор

Do you know of a good example of doing this with variadic templates?

JADE-iteGames
Автор

decltype(requires(){ requires requires(){ requires requires(){ requires true;};};}) myRequires() requires requires(){ requires requires() { requires requires() { requires requires(){ requires requires() { requires true; }; }; }; }; }
{ return requires(){ requires requires(){ requires true;};};}



This is valid C++20 code that will compile. And it's just the tip of the iceberg as you could expand this indefinitely and turn the nesting--like in Set Theory--into a mathematical language.

think
Автор

Hey, is there a way to use concepts to help compiler in doing CTAD? I have a use case for FFT (Fast Fourier Transform) which either takes std::complex<double> as T, or my custom class Modulo<MOD> where MOD is of type uint64_t (Formally known as Number Theoretic Transform, but the algorithm is same).

Currently, I am using

template <class T, const int64_t MOD>
vector<T>& FFT_internal(vector<T>& a, bool invert=false);

(I want to access MOD value whenever Modulo<MOD> is used, and ignore MOD if std::complex<double> is used). But I can't use FFT_internal(arr1) directly here, as I need to pass MOD and T explicitly. I am wondering if I can deduce MOD in constexpr context or in concepts

ConceptInternals
Автор

I wonder why you still need auto


I guess it's there for the sake of adding multiple concepts to single variable, so why not to allow dropping auto when there's only one concept used?

NoNameAtAll
Автор

Can you recommend a good C++ or general programming book for a beginner?

yusufgillani
Автор

it seems like you should be able to write `floating_point val = go(1.2, 2.3f)`. I dont get why there has to be an auto in between if it already knows its a concept auto deduction.

loomismeister
Автор

I've read most of the comments here. Here some people compare very conveniently for themselves one solution that checks some conditions at the compile time with code that doesn't (and can't). If we rightfully compare a similar code, we get just auto sum(auto a, auto b) { return a+b; }. Yeah, it's more simple than with generics in other languages. And these people somehow manage to make a bad opinion about the language in this situation. I'm just surprised how it's even possible to be so convenient (about some people here)

keshkek
Автор

Hello. Why is this possible:
const floating_point auto val = 1.2;
Here the const referes to the concept? Why does this work?

manuelm.
Автор

Thank you very much for explaining all of this! Concepts seems quite readable indeed, but I would not to like to see this terse syntax in the code.

ashrasmun
Автор

Hey Jason! Thanks for your excellent videos and tutorials.

Do you see any possible pitfalls or gotchas with the features that are coming in? Something programmers should be aware of?

TomaszWiszkowski
Автор

I think that static_assert does the job if it comes to input variables. You can specify what message the programmer sees on the wrong input.

scshout