static constexpr variable vs function

constexpr functions Functions have an advantage that free variables do not have (until C++14 that is): they can easily be templated without some class boilerplate. That means you can have your pi with a precision depending on a template argument: template<typename T> constexpr T pi(); template<> constexpr float pi() { return 3.14f; } template<> constexpr … Read more

When would I use std::integral_constant over constexpr?

Template integral_constant defines a type, keyword constexpr defines a constant. For example std::true_type is std::integral_constant<bool, true>. One of the usage examples is tag-dispatching. template<typename T> void use_impl(const T&, std::false_type) { } template<typename T> void use_impl(const T&, std::true_type) { } template<typename T> void use(const T& v) { use_impl(v, typename std::is_integral<T>::type()); } Live example

Equivalent ternary operator for constexpr if?

No, there is no constexepr conditional operator. But you could wrap the whole thing in a lambda and immediately evaluate it (an IIFE): template<typename Mode> class BusAddress { public: explicit constexpr BusAddress(Address device) : mAddress([&]{ if constexpr (Mode::write) { return device.mDevice << 1; } else { return (device.mDevice << 1) | 0x01; } }()) { … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)