English 中文(简体)
What do you dislike most about some of your favorite C++0x features? [closed]
原标题:
  • 时间:2010-01-10 19:44:45
  •  标签:
  • c++
  • c++11

While I am excited that C++0x will be much more fun to program in than C++98, I sometimes feel that some of the new features leave something important to be desired.
For e.g. initializer lists can not be deduced as references to arrays, variadic templates don t allow for member packs or arbitrary expression expansion, local classes can t be templates or contain templates or have in-class member initializers, lambdas can t be templates, constexpr can t help with compile time processing of string literals, user defined string literals can t be templates (whereas user defined number literals can be), decltype behaves significantly different in certain cases based on whether you parenthesize its operand or not (would have preferred a separate exprtype ).

I recognize that the standard s committee had to make some very difficult choices and compromises (since it really isn t meant to innovate, and because it has fairly limited resources), and I respect them deeply and am very grateful to them for doing what they do. This post isn t meant to denigrate their efforts (I am very much looking forward to using C++0x) - but to gauge how strongly others feel about some of these features.

With that in mind, I pose to you the following questions:

1) What are the new features that you are completely satisfied with?
2) What are the new features that you are partially satisfied with - and what would it take to make you more satisfied?
3) What are the new features that you wish had definitely not been added?

For a list of all the features, I will refer you to Stroustrup s List.

Thanks!

问题回答

I m very annoyed by many things in C++0x. All of them from the same reason -- while the new features are absolutely brilliant, the need of backwards-compatibility makes many of them look like ugly hacks...

Example 1:

SequenceClass(std::initializer_list<int> list);

instead of

SequenceClass(int... list); // or other nice in-language way

Example 2:

class D [[base_check]] : public B {
    void sone_func1 [[override]] ();

instead of

class D : public B {
    override void sone_func1 ();

Example 3:

std::shared_ptr<Target> m_target;

instead of

Target ^ m_target;

... okay, that last one is my own happiness :>

Of course all of these are subjective -- many people prefer it otherwise. What annoys me is the fact that we have to keep backwards compatibility so the language can t fully evolve. This is ESPECIALLY annoying in cases of safety -- I d really like to see C-style casts go away...

I really hope that C++ will someday adapt a "deprecation" mechanism, akin to what Khronos did to OpenGL since 2.0.

It s good they have alignment and memory model and thread local stuff. That should have been in ten years ago and there s no reason it should have taken so long.

The delegating constructors is something I wanted forever, but the implementation is horrible. If that s the best they can do it should be removed.

Pretty much everything else is just added complication and yet more initializer list nonsense. Which is why it s impossible to make delegating constructors properly. They should be trying to simplify the language, not add yet more metaprogramming complexity that makes so many problems.

  1. lambdas, auto, rvalue references
  2. templated typedefs; I think the syntax is awkward, but I m glad they exist in some form
  3. Concepts. Oh wait... I win




相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签