elbeno / constexpr Goto Github PK
View Code? Open in Web Editor NEWExperiments with constexpr
License: MIT License
Experiments with constexpr
License: MIT License
Counter does not seem to be counting up.
∴ clang -std=c++1z -I../include cx_counter.cpp
cx_counter.cpp:6:3: error: static_assert failed "counter(1)"
static_assert(cx::counter() == 1, "counter(1)");
^ ~~~~~~~~~~~~~~~~~~
cx_counter.cpp:7:3: error: static_assert failed "counter(2)"
static_assert(cx::counter() == 2, "counter(2)");
^ ~~~~~~~~~~~~~~~~~~
cx_counter.cpp:8:3: error: static_assert failed "counter(3)"
static_assert(cx::counter() == 3, "counter(3)");
^ ~~~~~~~~~~~~~~~~~~
3 errors generated.
With GCC < 9.0, the bug 67371 - Never executed "throw" in constexpr function fails to compile gives errors.
It has been solved for GCC >= 9.0 with 86678 - constexpr evaluation incorrectly diagnoses unevaluated call to non-constexpr function.
A workaround is to add in "cx_math.h":
// GCC
// Bug 67371 - Never executed "throw" in constexpr function fails to compile
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86678
// Fixed for GCC 9.
#if defined(__GNUC__) && (__GNUC__ < 9)
# define BUG_67371
#endif
and modify the constexpr long double floor(long double x)
and constexpr long double ceil(long double x)
functions the following way:
[...]
#ifndef BUG_67371
throw err::ceil_runtime_error();
#endif // BUG_67371
[...]
I build with -fno-rtti -fno-exceptions
so the code fails to build due to various run-time exceptions been thrown in your code. Care to make exception support optional?
Hey
Please could you say which license you're releasing this under.
Thank you!
Hi,
The partial specializations provided for cpp14_promoted in cx_math.h (https://github.com/elbeno/constexpr/blob/master/src/include/cx_math.h#L872) are ambiguous.
This can also be seen by testing with some main stream compilers: https://godbolt.org/z/rGfcGzKfh
The easiest fix is to provide an explicit specialization for when the types are both long double
:
template < >
struct cpp14_promoted < long double , long double >
{
using type = long double ;
} ;
I cannot use the string encryption at all. Throws errors immediately and crashes the compiler with "Internal error during IMAGE:BuildImage" LNK1000 and MSB6006 "link.exe" exited with code 1000 and C1001 "An internal error has occurred in the compiler." Using Visual Studio 2015 Update 2
What's in my code:
void Test()
{
std::string test = strenc("Test String");
}
error: ‘struct cx::array<T, N>::inserter<I, typename std::enable_if<(I == 0)>::type>’ redeclared with different access
Consider the following IEEEish assumption:
The widest floating point type can't exactly represent a bigger range of integers than the widest integer type. (that is, if we exceed the limits of widest int we're in a zone that is definitely not precise enough to have a fractional part, since it's not even good enough for integers)
I understand that this is quite dubious, almost unacceptable and nearly heretical, but look at my glorious trunc!
template <typename IntMax = std::intmax_t, typename Float = float>
[[nodiscard]] constexpr
Float trunc(Float f)
{
return abs(f) <= std::numeric_limits<IntMax>::max()
? static_cast<IntMax>(f)
: f;
}
I was wondering as to the nature of the syntax appearing many times in your code, with the use of the ternary operator, for example:
return true ? detail::md5::md5(s) : throw err::md5_runtime_error;
What is the benefit of this? why not just return detail::md5::md5(s)
?
After all, to my understanding, the exception will never be evaluated at runtime. Maybe there is some added value to this at compile time? If so, what is it?
thank you in advance.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.