Haskell style “Maybe” type & *chaining* in C++11

Good start, but I think you’re over-engineering in your zeal to make your class foolproof. Personally I’d recommend ‘worse is better’. First, let’s reuse Boost.Optional: struct nothing_type { template<typename T> operator boost::optional<T>() const { return {}; } }; constexpr nothing_type nothing; template<typename T> boost::optional<T> just(T&& t) { return std::forward<T>(t); } template<typename Option, typename Functor> auto … Read more

How useful would Inheriting Constructors be in C++?

2) Are there any technical reasons you can think of that would preclude “perfect forwarding constructors” from being an adequate alternative? I have shown one problem with that perfect forwarding approach here: Forwarding all constructors in C++0x . Also, the perfect forwarding approach can’t “forward” the expliciteness of base-class constructors: Either it is always a … Read more

Is there a safe way to have a std::thread as a member of a class?

You can use a thread in combination with move semantics: class MyClass final { private: std::thread mythread; void _ThreadMain(); public: MyClass() : mythread{} // default constructor { // move assignment mythread = std::thread{&MyClass::_ThreadMain, this}; } }; The move assignment operator is documented on the following page. In particular, it is noexcept and no new thread … Read more

Is the void() in decltype(void()) an expression or is it a function type?

Using a hyperlinked C++ grammar, the parsing of decltype(void()) is: decltype( expression ) decltype( assignment-expression ) decltype( conditional-expression ) … lots of steps involving order of operations go here … decltype( postfix-expression ) decltype( simple-type-specifier ( expression-listopt ) ) decltype( void() ) So void() is a kind of expression here, in particular a postfix-expression. Specifically, … Read more

What’s the right way to specialize a template when using “extern template”?

extern template class A<long>; This line says that A<long> is to be explicitly instantiated according to the definitions the compiler has already seen. When you add a specialization later, you break that meaning. Add a declaration of your specialization to the header file. template <typename T> struct A { /*…*/ }; template<> int A<long>::get() const; … Read more

Is empty struct defined by C++ standard?

There is a section to add this kind of construct as part of the Variant proposal (n4542). After being voted on, What do we want to call the “empty_t” stand-in type? empty_t 4 empty 4 one_t 1 blank 6 blank_t 7 monostate 7 Runoff: blank* 3 monostate 8 the agreed upon name would be: std::monostate. … Read more

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