Linked Questions
17 questions linked to/from constexpr overloading
5
votes
0
answers
117
views
C++ constexpr overload, different code for compile-time and runtime [duplicate]
constexpr void X() {
/* code, that can be executed at compiletime */
}
void X() {
/* code, that does the same as above, but is optimized for runtime, eg.
including caching, assembler code, ... ...
user avatar
user10043112
42
votes
5
answers
8k
views
Is is_constexpr possible in C++11?
Is it possible to produce a compile-time boolean value based on whether or not a C++11 expression is a constant expression (i.e. constexpr) in C++11? A few questions on SO relate to this, but I don't ...
30
votes
1
answer
15k
views
Guidelines to do constexpr operator-overloading?
Consider a simple int Wrapper class with overloaded multiplication operator*= and operator*. For "old-style" operator-overloading, one can define operator* in terms of operator*=, and there are even ...
11
votes
4
answers
1k
views
constexpr question, why do these two different programs run in such a different amount of time with g++?
I'm using gcc 4.6.1 and am getting some interesting behavior involving calling a constexpr function. This program runs just fine and straight away prints out 12200160415121876738.
#include <...
14
votes
3
answers
6k
views
constexpr, static_assert, and inlining
I previously asked about function overloading based on whether the arguments are constexpr. I'm trying to work around the disappointing answer to that question to make a smarter assert function. This ...
11
votes
1
answer
2k
views
Function returning constexpr does not compile [duplicate]
Why doesn't this compile:
Could there be a problem with a string as a return type?
constexpr std::string fnc()
{
return std::string("Yaba");
}
18
votes
2
answers
4k
views
Can I detect at compile time "function arguments" that are compile-time constants
Can I detect at compile time whether "function arguments"1 are compile-time constants?
For example a function print(int i) that can print "constant 5" if called as print(5) but "non-constant 5" if ...
17
votes
2
answers
774
views
Determine `constexpr` execution - during compilation or at runtime?
Is there a way to achieve different behaviour of a constexpr function in the compilation phase and at runtime?
Consider the following example (using a theoretical feature from D: static if):
...
14
votes
2
answers
4k
views
Constexpr and SSE intrinsics
Most C++ compilers support SIMD(SSE/AVX) instructions with intrisics like
_mm_cmpeq_epi32
My problem with this is that this function is not marked as constexpr, although "semantically" there is no ...
25
votes
1
answer
759
views
Implementing is_constexpr_copiable
I tried to implement a value template similar to std::is_constructible with the exception to only be true when the type is copiable in a constexpr environment (i.e. its copy constructor is constexpr ...
8
votes
1
answer
829
views
`noexcept` behavior of `constexpr` functions
The wording of [expr.unary.noexcept] changed in C++17.
Previously (n4140, 5.3.7 noexcept operator [expr.unary.noexcept]), my emphasis:
The result of the noexcept operator is false if in a ...
2
votes
3
answers
1k
views
Is constexpr useful for overload
Is there a way in c++ to get a different overload called based on the runtime/compile time constness of an input? My version(12) of MSVC can't do this using constexpr. Reading c++ documentation, I am ...
11
votes
1
answer
263
views
Static assert that passes if expression is not known at compile time [duplicate]
I want to implement my_static_assert that slightly differs from c++17 single-parametric static_assert: if condition inside my_static_assert is not known at compile time, it should pass.
The second ...
4
votes
3
answers
300
views
Overload function for arguments (not) deducable at compile time
Is there a way to overload a function in a way to distinguish between the argument being evaluable at compile time or at runtime only?
Suppose I have the following function:
std::string lookup(int ...
4
votes
2
answers
903
views
Implicitly convert number to integral const
Suppose I have the function:
template<size_t N>
void foo(std::integral_constant<size_t,N>);
Right now to use it I do this:
constexpr size_t myNum = 12;
foo(std::integral_constant<...