← Back to team overview

unity-dev team mailing list archive

[Ayatana-dev] C++0x in unity - call for objections

 

Hi all,

So C++0x, the latest C++ standard is just about ready for final, and its
damn sexy. G++ supports it with the -std=x++0x flag but before we go
ahead and start putting crack in to unity, I'd like to hear reasons that
we shouldn't start using C++0x stuff like lambda's in unity. speak now
or I’m gonna add lambda's to everything I see.

I don't expect all of you to have read the C++0x spec, but some
highlights are:

Type inference with the auto keyword, kind of like vala's var keyword,
you can negate the need to strongly type a variable if you are not sure
what a function is going to receive, dangerous, but useful with template
programming. 


> auto some_strange_callable_type = boost::bind(&some_function, _2,
_1,  some_object); 
> auto other_variable = 5; "


constant expressions, lets you turn what would normally horrible #DEFINE
code in to expressions evaluated at compile time ie:

> constexpr int get_five() {return 5;}
> int some_value[get_five() + 7]; //create an array of 12 integers.
legal C++0x

or 
> constexpr double acceleration_due_to_gravity = 9.8;
> constexpr double moon_gravity = acceleration_due_to_gravity / 6.0;


Foreach - okay not named that, but that's what it is. easy loops over
elements;

> int my_array[5] = {1, 2, 3, 4, 5};
> for (int &x: my_array) {
>     x *= 2;
> }

Lamda's - Does what it says, apart from its C++ so there is a bunch of
extra neat things it can do which you never will. the syntax is a little
strange to look at at first;

> [](int x, int y) { return x + y; }

an example using std::for_each which normally accepts a Sort function or
something like that

> std::vector<int> some_list;
> int total = 0;
> std::for_each(some_list.begin(), some_list.end(), [&total](int x) {
>   total += x;
> });

a nullpointer constant to get rid of the 0/NULL crapfest. nullptr_t

sizeof(SomeType::member) is now legal, woo.

Tuples, tuples are awesome and you should love them. basically lets you
make a container with objects of any type.

> typedef std::tuple <int, double, long &, const char *> test_tuple;

Hash tables in the standard library is nice

regular expressions in the standard library too


There is also a bunch more cool stuff like wrapper references, but i'm
not gonna go in to that.

Thoughts, opinions? yay? nay? +1? -1? 
-- 
Gordon Allott
Canonical Ltd.
27 Floor, Millbank Tower
London SW1P 4QP
www.canonical.com

Attachment: signature.asc
Description: This is a digitally signed message part


Follow ups