Simplest way to determine return type of function

You can leverage std::function here which will give you an alias for the functions return type. This does require C++17 support, since it relies on class template argument deduction, but it will work with any callable type: using ReturnTypeOfFoo = decltype(std::function{foo})::result_type; We can make this a little more generic like template<typename Callable> using return_type_of_t = … Read more

Why is std::iterator deprecated?

From the proposal that suggested its deprecation: As an aid to writing iterator classes, the original standard library supplied the iterator class template to automate the declaration of the five typedefs expected of every iterator by iterator_traits. This was then used in the library itself, for instance in the specification of std::ostream_iterator: template <class T, … Read more

how to convert filesystem path to string

To convert a std::filesystem::path to a natively-encoded string (whose type is std::filesystem::path::value_type), use the string() method. Note the other *string() methods, which enable you to obtain strings of a specific encoding (e.g. u8string() for an UTF-8 string). C++17 example: #include <filesystem> #include <string> namespace fs = std::filesystem; int main() { fs::path path{fs::u8path(u8″愛.txt”)}; std::string path_string{path.u8string()}; } … Read more

Why are are std::allocator’s construct and destroy functions deprecated in c++17?

The allocator requirements table says that construct(c, args), if provided, must “construct an object of type C at c“. It says absolutely nothing about 1) what arguments are to be passed to C‘s constructor or 2) how these arguments are to be passed. That’s the allocator’s choice, and in fact two allocators in the standard … Read more

Is stateful metaprogramming ill-formed (yet)?

This is CWG active issue 2118: Defining a friend function in a template, then referencing that function later provides a means of capturing and retrieving metaprogramming state. This technique is arcane and should be made ill-formed. Notes from the May, 2015 meeting: CWG agreed that such techniques should be ill-formed, although the mechanism for prohibiting … Read more

reinterpret_cast creating a trivially default-constructible object

There is no X object, living or otherwise, so pretending that there is one results in undefined behavior. [intro.object]/1 spells out exhaustively when objects are created: An object is created by a definition ([basic.def]), by a new-expression ([expr.new]), when implicitly changing the active member of a union ([class.union]), or when a temporary object is created … Read more

Strongly typed using and typedef

Here’s a minimal complete solution that will do what you want. You can add more operators etc to make the class more useful as you see fit. #include <iostream> #include <string> #include <map> // define some tags to create uniqueness struct portal_tag {}; struct cake_tag {}; // a string-like identifier that is typed on a … Read more

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