Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for the latest C++ standard #596

Closed
wants to merge 1 commit into from
Closed

add support for the latest C++ standard #596

wants to merge 1 commit into from

Conversation

hdastwb
Copy link
Contributor

@hdastwb hdastwb commented Apr 4, 2013

Thus, people can use some of the new features listed here:
http://www.stroustrup.com/C++11FAQ.html

or here:
http://en.wikipedia.org/wiki/C%2B%2B11

with newer compilers

@kaeza
Copy link
Contributor

kaeza commented Apr 4, 2013

Why?

@hdastwb
Copy link
Contributor Author

hdastwb commented Apr 4, 2013

C++98:

int arr [] = {1, 2, 3, 4};
vector<int> vec (arr, arr + 4);
for (vector<int>::iterator vit = vec.begin(); vit != vec.end(); ++vit) cout << *vit << endl;

C++11:

vector<int> vec {1, 2, 3, 4};
for (auto val : vec) cout << val << endl;

@hdastwb
Copy link
Contributor Author

hdastwb commented Apr 4, 2013

C++98:

int sum(int count, ...)
{
    va_list vl;
    va_start(vl, count);
    int sum = 0;
    for (int i = 0; i < count; ++i)
    {
        sum += va_arg(vl, int);
    }
    va_end(vl);
    return sum;
}

C++11:

int sum(int i)
{
    return i;
}

template <typename... VA>
int sum(int i, VA ...va)
{
    return i + sum(va...);
}

@hdastwb
Copy link
Contributor Author

hdastwb commented Apr 4, 2013

C++98:

class funky
{
public:
    bool operator() (int i)
    {
        return i < 4;
    }
};

cout << count_if(vec.begin(), vec.end(), funky()) << endl;

C++11:

cout << count_if(vec.begin(), vec.end(), [](int i){return i < 4;}) << endl;

@hdastwb
Copy link
Contributor Author

hdastwb commented Apr 4, 2013

C++11:

double operator"" _bin(const char* lit)
{
    if (*lit == '0') return 0;
    double res = 0;
    while (*lit and *lit != '.') res *= 2, res += *lit++ - '0';
    if (*lit) ++lit;
    else return res;
    double di = 1;
    while (*lit) di *= 2, res += (*lit++ - '0')/di;
    return res;
}

. . .

cout << -11.1_bin << endl;

C++98:
???

@kaeza
Copy link
Contributor

kaeza commented Apr 4, 2013

Good! I only asked "why?" and got you to post the entire C++ 11 specification.
Here, have a cookie.

@hdastwb
Copy link
Contributor Author

hdastwb commented Apr 4, 2013

*munch

I haven't even mentioned the new smart pointer, timing, threading, or regular expression libraries (though some of those (regexes) are still not supported by GCC)

@PilzAdam
Copy link
Contributor

PilzAdam commented Apr 4, 2013

"(though some of those (regexes) are still not supported by GCC)" Thats the reason why we wont use it.

@kwolekr
Copy link
Contributor

kwolekr commented Apr 5, 2013

hdastwb, thanks to this pull request, we know specifically why C++11 shouldn't be used. Although it does marginally increase the expressiveness of C++, we would never benefit from that. The code snippets you pasted are pretty crazy, all examples of things that would never be allowed in Minetest's codebase. Code needs to be really simple and stupid, not relying on such high-level features. That last example with the _bin operator is especially insane, and brings no benefit at all over simply passing that literal to a function called bin(). Lots of potential for obsfucation, though.
Surprisingly, you failed to mention the inclusion of std::unordered_map and std::unordered_set, though, a much more convincing reason to support C++11 (however, I plan on including a thread-safe lockless hashtable, which somewhat invalidates the need for this).
As for merging this pull request, that's a big 'no', not for the lack of need for C++11, but because my platform doesn't even support C++11. I use gcc 4.2.2, which does not recognize -std=c++11 as a valid option at all. So, I wouldn't even be able to develop anymore without using a different compiler. It also would pull in gcc47 as a dependency on FreeBSD, which is clearly undesirable.

@kwolekr kwolekr closed this Apr 5, 2013
@rdnuk
Copy link

rdnuk commented Feb 16, 2015

With all due respect why has this been closed within 24 hours.... why has it not been left for discussion. @kwolekr listed his reasons why it shouldn't be merged but what if other users have ideas on how to combat that. I understand your reasons, i just don't understand why this wasn't given a chance to be discussed further. heck only 2 core-developers commented on it and one of them barely said much.

To note I'm not a C++ developer. but I have a basic understanding due to developing in other languages.
from my understanding IF C++11 was fully supported with all system's then its would likely drastically lower the code base of minetest. and the new features that @hdastwb has mentioned in various post would hopefully make minetest perform better??

All im saying is why are we knocking it before anyones had chance to talk about it properly.

I awaits to have my head bitten off and raged at :/

@nerzhul
Copy link
Member

nerzhul commented Feb 16, 2015

personally i agree with C++11 if windows 7 and more + supports it (windows XP isn't supported by M$) Ubuntu was okay, we must look at debian to see if it's supported. On archlinux it's good, on recent Fedora and redhat too, on FreeBSD it's good.

What we need to use in c++11, i think:

std::regex
std::mutex
std::thread

@kahrl
Copy link
Contributor

kahrl commented Feb 16, 2015

I'm not convinced that we need to switch from jthread to std::thread/std::mutex. For example, on Windows std::mutex seems to be a whole lot slower than critical sections (which is what JMutex uses): http://stackoverflow.com/a/24470878

@Zeno-
Copy link
Contributor

Zeno- commented Feb 16, 2015

I have said it before and I'll say it again: a lot of people still use LTS operating systems that do not support C++11. These are people who run servers. If we discount those people then the audience is decreased.

My VPS does not (fully) support C++11 and I know at least two other people who run (popular or semi-popular) servers that are in the same boat.

To switch to C++11 would require a compelling reason, IMO. This is not compelling enough.

@nerzhul
Copy link
Member

nerzhul commented Feb 16, 2015

We need to wait 2 years more :(

@Zeno-
Copy link
Contributor

Zeno- commented Feb 16, 2015

Maybe not 2 years.

But this PR was not and is not worth the effort and disruption (IMO)

@PilzAdam
Copy link
Contributor

@nerzhul

Ubuntu was okay

No, there is a currently supported LTS version of Ubuntu that does not support c++11 (I happen to use it and as a core dev I'd like to be able to compile Minetest ;-))

@est31 est31 mentioned this pull request Jun 5, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants