When to use constinit and consteval? [duplicate] - c++

This question already has answers here:
What is consteval?
(1 answer)
What is `constinit` in C++20?
(2 answers)
Closed 2 years ago.
The usage of constexpr is quite straightforward which is to make sure the code can be evaluated at the compile time itself.
But the latest features of C++ 20 which provides constinit and consteval are little bit confusing. Can someone provide the practical use case of constinit and consteval?

Related

Confused by notation in boost::thread example [duplicate]

This question already has answers here:
What's the difference between parentheses and braces in c++ when constructing objects
(1 answer)
what is aggregate initialization
(2 answers)
Closed 9 months ago.
From boost libraries, I found this example
I marked a line with a red arrow, indicating the notation that is confusing me.
Is this special to boost or is this some sort of anonymous function syntax? I wasn't aware that C++ or C had such notation. I only kind of recognize it from python and java experience.

Use of goto statement [duplicate]

This question already has answers here:
What is wrong with using goto? [duplicate]
(6 answers)
GOTO still considered harmful? [closed]
(49 answers)
Closed 3 years ago.
In my CPP class my professor strictly asked us to not to use goto statement as long as possible. Why is so, as I think there are no memory or any issues whatsoever with goto?

How can I Tell if a Type is a Functor? [duplicate]

This question already has answers here:
Find out whether a C++ object is callable
(8 answers)
Can std::is_invocable be emulated within C++11?
(1 answer)
Closed 3 years ago.
In c++17 I have is_invocable to match function pointers, lambdas, and functors.
But what if I'm trapped on c++14? Do I have a type trait, or can I write one, which will match all of these?
I've tried is_function but that only works on function pointers.
Yes you can, std::is_invocable is a library function which requires no compiler support. You can just rip the implementation from an STL of your choice.
For example, you can find LLVM implementation of __invokable (to which std::is_invocable forwards all the logic in LLVM's STL) here: https://android.googlesource.com/platform/ndk/+/5b3a49bdbd08775d0e6f9727221fe98946f6db44/sources/cxx-stl/llvm-libc++/libcxx/include/type_traits
(I was thinking of extracting it and posting here, but it seems to be too big for a post. On a lighter note, I find difference in spelling - invocable vs invokable - amusing.)

Sorting list of ints. TMP [duplicate]

This question already has answers here:
Quick sort at compilation time using C++11 variadic templates
(2 answers)
Closed 7 years ago.
I wonder it it is possible to sort numbers during compilation? I mean something like that:
template<int...>
void sort(){
...
}
And:
sort<2,4,5,13,453>();
And I don't ask of solution or something like that. Please give me a hint or reference me.
Since C++ template system is known to be turing-complete, you can in principle compute everything that is computable at compile time. That includes sorting algorithms.

question about auto in c++ [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
Is there any reason to use the ‘auto’ keyword in C / C++?
can anybody explain me purpose of auto keyword in c++? thanks
It's useless and is left for old code compatibility. Long ago you used it to say that a variable is automatic, this is no longer useful - all variables witout other qualifiers are treated as automatic (stack-allocated).