Why is a constructor necessary in a const member struct?

From ยง8.5 [dcl.init]/7: If a program calls for the default initialization of an object of a const-qualified type T, T shall be a class type with a user-provided default constructor. The default constructor of AClass default-initializes the const member (see below), so that member must have a user-provided default constructor. Using = default does not … Read more

Does using std::array lead to code bloat? [duplicate]

I wouldn’t worry about it. If you look at the interface of std::array<T, N>, it is very small and most member functions (basically providing wrappers for pointer manipulation) are one-liners that will be completely optimized away / inlined by any decent compiler on Release mode optimization levels. Furthermore, you don’t pay for what you don’t … Read more

Strange values in a lambda returning initializer_list

From: http://en.cppreference.com/w/cpp/utility/initializer_list The underlying array is not guaranteed to exist after the lifetime of the original initializer list object has ended. The storage for std::initializer_list is unspecified (i.e. it could be automatic, temporary, or static read-only memory, depending on the situation). I don’t think the initializer list is copy-constructable. std::set and other containers are. Basically … Read more

Expression templates and C++11

I was wondering whether lambdas together with move semantics or any other new feature can do as good as ETs. Any thoughts? Quick Answer Move semantics are not a total panacea on their own –techniques such as expression templates (ETs) are still needed in C++11 to eliminate overheads such as moving data around! So, to … Read more

std::mem_fun vs std::mem_fn

std::mem_fun is deprecated. std::mem_fn can do everything it does, and it does it more conveniently. The relation between the two is the same as the relation between std::bind1st/std::bind2nd and the C++11 std::bind. Both std::mem_fn and std::bind were developed and mastered after std::bind1st and std::mem_fun were made into the C++98 Standard. So that means we had … Read more

When is std::chrono epoch?

It is a function of both the specific clock the time_point refers to, and the implementation of that clock. The standard specifies three different clocks: system_clock steady_clock high_resolution_clock And the standard does not specify the epoch for any of these clocks. Programmers (you) can also author their own clocks, which may or may not specify … Read more

Is std::string ref-counted in GCC 4.x / C++11?

Looking at libstdc++ documentation I find (see the link for more info): A string looks like this: [_Rep] _M_length [basic_string<char>] _M_capacity _M_dataplus _M_refcount _M_p —————-> unnamed array of char_type So, yes it is ref counted. Also, from the discussion here: Yes, std::string will be made non-reference counting at some point, but as a non-reference-counted string … Read more

Cannot use .begin() or .end() on an array

Arrays have no member functions as they aren’t a class type. This is what the error is saying. You can use std::begin(arr) and std::end(arr) from the <iterator> header instead. This also works with types that do have .begin() and .end() members, via overloading: #include <array> #include <vector> #include <iterator> int main() { int c_array[5] = … Read more

C++11: I can go from multiple args to tuple, but can I go from tuple to multiple args? [duplicate]

Try something like this: // implementation details, users never invoke these directly namespace detail { template <typename F, typename Tuple, bool Done, int Total, int… N> struct call_impl { static void call(F f, Tuple && t) { call_impl<F, Tuple, Total == 1 + sizeof…(N), Total, N…, sizeof…(N)>::call(f, std::forward<Tuple>(t)); } }; template <typename F, typename Tuple, … Read more

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