« first day (1247 days earlier)      last day (1589 days later) » 

8:55 AM
Is list initialization introduced in C++11 implemented by initializer_list?
 
9:42 AM
hello
 
@Rick I don't think list initialization always need initializer_list
I see initializer_list as the library component to help make list initialization customizable/acessible to the programmer
 
10:06 AM
But for those examples about list initialization, I observer there's an overloaded function with initializer_list as a parameter.
Take vector as an example, vector( std::initializer_list<T> init, const Allocator& alloc = Allocator() ); since c++11
and vector& operator=( std::initializer_list<T> ilist );(3) (since C++11
 
right, but when you use list-initialization syntax to initialize aggregates there's not initializer list involved
so, is initializer_list used for some types in the stdlib, yes
it it generally necessary for the syntactic construct, no
Just look at std::array
 
I used to see the list initialization as a language level feature. Now I am starting to think that maybe it's not a language level feature but merely a few extra member functions/constructors.
 
the fallback to non-initializer_list constructor or aggregate initialization is clearly a language feature
 
Let me take a quick look
Ah I see. Ok I get it.
I have another question related to list initialization.
Why is it considered to be "something new" in C++11? As you said, we've used int a[] = {1,2,3,4,5} for a long time.
new for non built-in type (Class)?
 
it's a new concept that is a superset of the old aggregate initialization (or however it was called before).
 
10:25 AM
Ok. could make sense.
Thanks Peter
 
 
3 hours later…
1:35 PM
is it always good to declare variables as const?
even though it will certainly be altered later, but still it is good to declare it as const?
 
Hello everyone! I got a quick question, learning about inheritance and the current exercise starts with: 'for this exercise we use std::string as a base class although that's is bad practice - why is it bad practice?' (exercise is about hiding members)

Do you think that a very short summary of this is what the question is aiming at? https://stackoverflow.com/questions/6006860/why-should-one-not-derive-from-c-std-string-class
 
1:56 PM
@rezi inheriting from the stdlib in general is a bad practice because they aren't designed for it
 
2:07 PM
Ah thanks, going to add that!
 
 
1 hour later…
3:23 PM
Given a vector of some IListeners which have methods A() B() how would I go about making a function that will "call function F on each IListener"?

For example:
someFunction(vector, IListener::A)
would go through vector and call IListener.A()

I currently have a few places where I do the same loops but only change the function that is being called and would like to lift it to a method. Would something like std::map work perhaps?
*not std::map but std::transform i.e. mapping over
 
3:52 PM
@Ramzis technically yes but you'll end up using a lambda
sooo not sure it's worth it
 
oh yeah that makes sense, I was thinking about bind but that's the same I guess
 
at the end of the day sometimes a loop is the right option. If you have more code around that you're duplicating then it's worth making a method.
 
 
1 hour later…
5:21 PM
@Ramzis Just to be clear, the obvious options are: for (auto &a : yourVector) a.A(); and std::for_each(yourVector.begin(), yourVector.end(), [](auto &a) { a.A(); });. If you can use C++20, you can probably use a range instead of iterators, which can reduce the verbosity a bit, but if that's all you're trying to do, the range-based for is probably still going to be the simplest.
Oh, for both the loop and the for_each, you could use auto const &a if A() is a const member function.
@Ramzis Yes, close enough to the same--in fact, I think std::bind is a decent example of second system effect. It does a fine job of fixing the problems with std::bind1st and std::bind2nd, but I'm pretty sure I've never used it except in some example code showing how it can be used. For most practical purposes, lambdas render it obsolete.
 

« first day (1247 days earlier)      last day (1589 days later) »