Originally posted by Vistaus
View Post
Announcement
Collapse
No announcement yet.
GCC Developers Look At Transitioning Their Codebase To C++11
Collapse
X
-
- Likes 1
-
Originally posted by kpedersen View PostThis didn't compile on my RHEL 6 compiler (-std only goes up to 11). This is still our main server target unfortunately.
- Likes 4
Comment
-
Originally posted by nanonyme View PostDo also considering the bootstrappability requirement. You need an older GCC to build a newer GCC and unless you can have quite large version difference between the two, it will be quite painful for LTS distros.
Comment
-
Originally posted by AsuMagic View PostManual memory allocations are essentially always a terrible idea.
Most of the time you can do the job with unique_ptr and it will neatly manage the lifetime of the held object.
We're not yet at the point of a true garbage-collected language, but I don't want that. If I want true garbage collection, I'll use something other than C++.
Originally posted by AsuMagic View PostEven on the simplest stuff C++03 is annoying: No initializer lists, the stupid > > syntax rule, being unable to call a parent constructor or inherit from them...
Regarding the requirement of a space between template parameter brackets (i.e. "> >"), that's just silly. After the first time tripping over it, you just learn to put an extra pair of spaces inside your <>'s. Problem solved. It's not ideal, but I don't think it rises to the level of the rest of the items in your list.
I don't get your point about parent constructors - of course you can call constructors of your baseclasses! What C++11 adds is the ability for derived classes to forward baseclass constructors, or for constructors to explicitly call sibling constructors of the same type.
Originally posted by AsuMagic View Postauto is not only useful for "laziness". It is very convenient for metaprogramming, and allows avoiding needless verbosity or workarounds.
Originally posted by AsuMagic View PostSeriously, if you still are willingly using C-style arrays in 2019, I just don't ever want to have to deal with your code. I never ever found any reason not to use that other than pure masochism.
Code:int vals[] = { 1, 2, 3 };
Last edited by coder; 30 September 2019, 10:20 PM.
- Likes 1
Comment
-
Originally posted by tildearrow View PostAlso, is it possible to access the associated iterator using the for (type i: var) {} syntax? Will come in handy when having to erase stuff in arrays.
Anyway, if you might need to erase, I think your best options are:- use iterators
- iterate by index (if randomly-accessible container)
If an associative container, you can also erase by key, although that's a wasteful thing to do frequently.
Originally posted by tildearrow View PostI don't use chrono. Instead I use a custom C++ wrapper to struct timespec.
The learning curve on std::chrono is a little steep, but at least it has distinct types for absolute and relative measures of time. Flexibility over types and units is also nice, even if it does feel a bit awkward.
Originally posted by tildearrow View PostI never understood how to use λ's...
Also, spend some time becoming comfortable with std::bind. It's based on boost::bind, which had a significant impact on the way I write C++. Together, they enable a much more functional style, largely eliminating over-reliance on classes and inheritance.
Originally posted by tildearrow View Postconstexpr? I never knew about that.
There are many C++ features I have never used...- https://en.wikipedia.org/wiki/C%2B%2B11
- https://en.cppreference.com/w/cpp/language/history
- https://docs.microsoft.com/en-us/cpp...p?view=vs-2019
In my early years of using C++, I spent the time and read Stroustrup. If you're using it for anything serious, it's worth at least getting down to that level of detail. Scott Meyers' books and C++ Templates: The Complete Guide (Vandevoorde & Josuttis) took my C++ to the next level. Sad to say, Meyers' Effective Modern C++ isn't as approachable as his earlier works, but those are pre-C++11.
Originally posted by tildearrow View PostI only use C arrays for fixed-size ones or when I really desire speed. Otherwise I use std::vector
A big part of being a competent C++ programmer is learning the right container to use for the job.Last edited by coder; 30 September 2019, 10:24 PM.
Comment
-
-
As a Lisp user, my mind boggles at how you C++ programmers survived without lambda expressions. For people who are curious, they are just unnamed procedures that evaluate to a value. (aka function expressions)
Here’s a procedure in Scheme:
Code:(define (square x) (* x x))
Code:(define square [B](lambda (x) (* x x))[/B])
Code:((lambda (x) (* x x)) 5)
Code:const square = (x) => x * x
Code:[1, 2, 3, 4, 5].reduce((acc, curr) => acc + curr) // equals 15
Originally posted by coderSad to say, Meyers' Effective Modern C++ isn't as approachable as his earlier works, but those are pre-C++11.
Comment
-
Originally posted by coder View PostErr... you mean erase from vectors? You can overwrite array elements, but you can't erase them.
Anyway, if you might need to erase, I think your best options are:- use iterators
- iterate by index (if randomly-accessible container)
If an associative container, you can also erase by key, although that's a wasteful thing to do frequently.
Originally posted by coder View PostUm, why? And it doesn't help you, if you need to use something like std::condition_variable::wait_until(), which takes a std::chrono::time_point<> parameter.
The learning curve on std::chrono is a little steep, but at least it has distinct types for absolute and relative measures of time. Flexibility over types and units is also nice, even if it does feel a bit awkward.
Originally posted by coder View PostIt's an investment that will pay dividends.
Also, spend some time becoming comfortable with std::bind. It's based on boost::bind, which had a significant impact on the way I write C++. Together, they enable a much more functional style, largely eliminating over-reliance on classes and inheritance.
Well, you could do worse than spend some time reading these:- https://en.wikipedia.org/wiki/C%2B%2B11
- https://en.cppreference.com/w/cpp/language/history
- https://docs.microsoft.com/en-us/cpp...p?view=vs-2019
In my early years of using C++, I spent the time and read Stroustrup. If you're using it for anything serious, it's worth at least getting down to that level of detail. Scott Meyers' books and C++ Templates: The Complete Guide (Vandevoorde & Josuttis) took my C++ to the next level. Sad to say, Meyers' Effective Modern C++ isn't as approachable as his earlier works, but those are pre-C++11.
The point of std::array is to give you a convenient container interface with the same speed & constraints as a C array.
A big part of being a competent C++ programmer is learning the right container to use for the job.
Comment
-
Originally posted by cynical View PostAs a Lisp user, my mind boggles at how you C++ programmers survived without lambda expressions.
https://www.boost.org/doc/libs/1_31_...doc/index.html
And even before Boost introduce boost::bind(), STL had bind1st() and bind2nd():
https://www.boost.org/doc/libs/1_31_...bind/bind.html
https://en.cppreference.com/w/cpp/ut...ctional/bind12
Plus, for a lot of generic operations, we had pre-defined function templates:
(note the number of operations lacking version qualifiers)
But, before/besides that, it just meant that using generic algorithms and higher-order operations required writing a few more one-off functions and functors.
Originally posted by cynical View PostJavaScript also has a really fantastic syntax for them.
Originally posted by cynical View PostWhat do you mean? That book was fantastic!
My recollection is that his earlier C++ books started with a much more gentle tone, offering advice you can use straight away.
Comment
-
Originally posted by tildearrow View PostSo there is no way to do it using the easily-readable syntax? Oh....
Remember, they're called "range-based for-loops", for a reason. It's interesting to dig under the covers and see how the language implements them, if you're curious.
If your use case didn't involve modifying the container, you could maintain an index on the side. I'm sure I've done that, but I'm having a bit of trouble thinking of a good example of when it's needed.
Anyway, an important part of choosing the right container for your purpose is considering the circumstances under which its iterators are invalidated. For example, list insertions and removals don't affect iterators other than those to the element being removed. However, pretty much any operation changing a vector's size will invalidate its iterators.
Originally posted by tildearrow View PostBecause I use clock_gettime since I think it takes less time to execute.
https://en.cppreference.com/w/cpp/ch...stem_clock/now
If you can quantify any significant overhead, do let us know.
Comment
Comment