c++03

No type named 'unique_ptr' in namespace 'std' when compiling under LLVM/Clang

一曲冷凌霜 提交于 2019-11-29 08:37:40
I'm catching a compile error when attempting to use unique_ptr on Apple platforms with -std=c++11 : $ make c++ -std=c++11 -DNDEBUG -g2 -O3 -fPIC -march=native -Wall -Wextra -pipe -c 3way.cpp In file included ... ./smartptr.h:23:27: error: no type named 'unique_ptr' in namespace 'std' using auto_ptr = std::unique_ptr<T>; ~~~~~^ ./smartptr.h:23:37: error: expected ';' after alias declaration using auto_ptr = std::unique_ptr<T>; According to Marshall Clow, who I consider an expert on the C++ Standard Library with Clang and Apple : Technical Report #1 (TR1) was a set of library additions to the C+

How to simplify complicated SFINAE syntax, in pre-C++11, C++11, 14 and 17?

旧街凉风 提交于 2019-11-29 07:37:57
问题 This question was inspired by this answer. I wonder what are/were the best ways to simplify it in given standards. One I know and personally used/still use since C++14 is macro REQUIRES(x) : With definition: template<long N> struct requires_enum { enum class type { none, all }; }; #define REQUIRES(...) requires_enum<__LINE__>::type = \ requires_enum<__LINE__>::type::none, \ bool PrivateBool = true, \ typename std::enable_if<PrivateBool && (__VA_ARGS__), int>::type = 0 And use if even for non

Why do inline functions have external linkage by default?

梦想与她 提交于 2019-11-29 06:10:19
问题 The standard says that given a declaration of inline void foo(); that foo is an inline function with external linkage (because by default all function declarations have external linkage). This strikes me as odd. because the one definition rule section 3.2 (in both C++03 and C++11) say: 3 ... An inline function shall be defined in every translation unit in which it is used. 5 There can be more than one definition of a[n] ... inline function with external linkage (7.1.2) ... Given such an

“Constant expressions” prior to C++11

自闭症网瘾萝莉.ら 提交于 2019-11-29 06:01:06
The constexpr keyword was introduced in C++11, as (I think) was the corresponding idea of "constant expressions." However, this concept was implicitly present in C++98/c++03, since array declarations require a constant expression: // valid: int a[sizeof(int)]; int b[3+7]; int c[13/4]; const int n = 3; int d[n]; // invalid: int m = 4; int e[m]; There are other "constant expressions", i.e., expressions that can be (and/or must be) evaluated at compile-time; one example is template arguments. For pre-C++11, do the following exist, either in the C++98/03 standards or elsewhere? A complete list of

Is C++03 a new version of the C++ Standard or just a Technical Corrigendum (TC) of C++98?

十年热恋 提交于 2019-11-29 05:33:50
问题 I'm pretty sure I read on an authoritative source somewhere (I believe it was on the WG21 pages) that C++03 was not a technical corrigendum of C++98 but that it was a new release of the C++ Standard. But nontheless I see only -std=c++98 switch in GCC and others compilers and Alf P Steinbach made a few comments hinting at that it may indeed be a TC of C++98. So when I'm writing about "C++03", does it suffice mentioning C++98? As a related question, is it even wrong to use the term "C++03"?

How can I deploy a C++11 program (with dependencies) on CentOS 6, whose GCC is C++03?

流过昼夜 提交于 2019-11-29 02:25:15
问题 GCC is great with ABI-compatibility as long as you use the same C++ standard [1]. But it strikes me that if a shared library compiled by GCC 4.3 in C++03 mode exposes, say, a std::string , this is going to be a different std::string than that understood by an executable compiled by GCC 4.8 in C++11 mode. The reason I ask is that I am planning to deploy a program compiled by GCC 4.8 in C++11 mode on CentOS 6, whose maximum packaged GCC is 4.3... and some of the shared libraries (be they third

What is the C++03 memory model for concurrency?

风格不统一 提交于 2019-11-28 16:42:49
问题 What is the memory model for concurrency in C++03? (And, does C++11 change the memory model to support concurrency better?) 回答1: The C++ memory model is the specification of when and why physical memory is read/written with respect to C++ code. Until the next C++ standard, the C++ memory model is the same as C. In the C++0x standard, a proper memory model for multithreading is expected to be included (see here), and it will be part possibly of the next revision of the C standard, C1X. The

assigning char to int reference and const int reference in C++

社会主义新天地 提交于 2019-11-28 12:06:33
I noticed that assigning a char to a const int& compiles, but assigning it to a int& gives a compilation error. char c; int& x = c; // this fails to compile const int& y = c; // this is ok I understand that it is not a good practice to do this, but I am curious to know the reason why it happens. I have searched for an answer by looking for "assigning to reference of different type", "assigning char to a int reference", and "difference between const reference and non-const reference", and came across a number of useful posts ( int vs const int& , Weird behaviour when assigning a char to a int

Thread safety of C++ std Containers

牧云@^-^@ 提交于 2019-11-28 12:04:29
I read a lot of posts here with the question if the standard containers for C++ (like "list" or "map" are thread safe and all of them said that it is not in general. Parallel reads should be OK, but parallel writes or parallel reads and writes may cause problems. Now I found out that at www.cplusplus.com that accessing or modifying the list during most of the operations is safe. Some examples: map::find The container is accessed (neither the const nor the non-const versions modify the container). No mapped values are accessed: concurrently accessing or modifying elements is safe. map::insert

C++03. Test for rvalue-vs-lvalue at compile-time, not just at runtime

拟墨画扇 提交于 2019-11-28 06:51:39
In C++03, Boost's Foreach, using this interesting technique , can detect at run-time whether an expression is an lvalue or an rvalue. (I found that via this StackOverflow question: Rvalues in C++03 ) Here's a demo of this working at run-time (This is a more basic question that arose while I was thinking about this other recent question of mine . An answer to this might help us answer that other question.) Now that I've spelled out the question, testing rvalue-ness in C++03 at compile-time, I'll talk a little about the things I've been trying so far. I want to be able to do this check at