Pagini: [1]   În jos
  Imprimă  
Ajutor Subiect: C++ compiler upgrades on infoarena  (Citit de 3995 ori)
0 Utilizatori şi 1 Vizitator pe acest subiect.
pauldb
Nu mai tace
*****

Karma: 821
Deconectat Deconectat

Mesaje: 1.901



Vezi Profilul
« : Aprilie 28, 2013, 02:14:28 »

http://www.infoarena.ro/blog/cpp11
Memorat

Am zis Mr. Green
freak93
Echipa infoarena
Nu mai tace
*****

Karma: 342
Deconectat Deconectat

Mesaje: 819



Vezi Profilul
« Răspunde #1 : Aprilie 28, 2013, 02:19:50 »

Another cool thing:

Cod:
struct A {
int x = 2, y = 3;
};

No need for constructors anymore for simple stuff.
Memorat
cosmyo
Strain


Karma: 1
Deconectat Deconectat

Mesaje: 14



Vezi Profilul
« Răspunde #2 : Aprilie 28, 2013, 02:33:48 »

Foarte misto, bravo! Very Happy
Pentru al doilea feature se poate si pe set-uri din STL ?
Memorat
pauldb
Nu mai tace
*****

Karma: 821
Deconectat Deconectat

Mesaje: 1.901



Vezi Profilul
« Răspunde #3 : Aprilie 28, 2013, 03:11:31 »

Yes, you can do range-based for loops on any iterable container. That includes sets and maps:

Cod:
set<int> s = {5, 4, 3, 2, 1};
for (auto x: s) {
  cout << x << endl;
}

map<string, int> m = {{"john", 1}, {"mary", 2}};
for (auto e: m) {
  cout << e.first << " " << e.second << endl;
}
Memorat

Am zis Mr. Green
laurion
De-al casei
***

Karma: -41
Deconectat Deconectat

Mesaje: 102



Vezi Profilul
« Răspunde #4 : Aprilie 28, 2013, 12:05:53 »

Good stuff.

It's nice that we also have a standard container for constant sized, C-like, arrays:
Cod:
array<int, 3> arr = {1, 2, 3};
arr.size(); // it has the benefit that it knows its own size and stuff

Now introducing tuple<int,double,string,...>, which are like std::pair, but they can contain any number of elements. Yay, no more annoying custom structs or pairs of pairs of pairs gibberish.

And then there are hash_map and hash_set, which were previously only available in the ext directory, under __gnu_cxx.
Memorat
freak93
Echipa infoarena
Nu mai tace
*****

Karma: 342
Deconectat Deconectat

Mesaje: 819



Vezi Profilul
« Răspunde #5 : Aprilie 28, 2013, 14:47:17 »

Another 2 things:

to_string a function which conversts numeric types to std::string and std::tie. WIth std::tie you can do stuff like this

Cod:
auto a = std::make_tuple(0, "Hello world!", 5.5);

int x;
double y;
std::tie(x, std::ignore, y) = a;

And now x and y have the values a.first and a.second.
Memorat
alex_unix
Strain
*

Karma: 22
Deconectat Deconectat

Mesaje: 46



Vezi Profilul
« Răspunde #6 : Aprilie 28, 2013, 15:05:08 »

Era si cazul Tongue . Multumim ! Very Happy

The g++ 4.8 compiler also has some nice optimizer improvements, most of which are available since g++ 4.7 . Inline functions will be optimized even further if the compiler knows some additional information about function's parameters.
Cod:
inline int a (int x)
{
    if (x < 0)
    {
         // big code...
    }
    else
    {
        // big code...
    }
    return x;
}


For a(-1) the compiler will write just half of the code now. This feature is great if you inline large functions which are called many times.

Also non-inline functions are optimized.

Cod:
void f (bool x)
{
  if (!x)
    // code ...
  else
    // code ...
}

int main (void)
{
   // code...
  f(true);
  f(false);
  f(true);
  f(false);
  f(true);
  f(false);
   //code...
}


g++ will now produce two copies of f. One with x being true, while other with x being false. This leads to performance improvements previously possible only by inlining all calls. Cloning causes a lot less code size growth.

A string length optimization pass has been added since g++ 4.7. It attempts to track string lengths and optimize various standard C string functions ( strlen, strchr, strcpy, strcat, stpcpy and so on...).

Cod:
void x (char *a, char *b, char *c, char *d)
{
  strcpy (a, b);
  strcat (a, c);
  strcat (a, d);
}

becomes

void x (char *a, char *b, char *c, char *d)
{
  strcpy (stpcpy (stpcpy (a, b), c), d);
}


« Ultima modificare: Aprilie 28, 2013, 17:26:07 de către Petenchea Alexandru » Memorat
Pagini: [1]   În sus
  Imprimă  
 
Schimbă forumul:  

Powered by SMF 1.1.19 | SMF © 2006-2013, Simple Machines