c++03

Why doesn't ::boost::tie work with BOOST_FOREACH?

扶醉桌前 提交于 2019-12-23 15:55:25
问题 I want to use BOOST_FOREACH to iterate over a boost::ptr_map , and came across this neat-looking solution. I would prefer using this for better readability, as against the other solutions given. I wrote the following code: boost::ptr_map<int, std::string> int2strMap; int x = 1; int2strMap.insert(x, new std::string("one")); int one; std::string* two; BOOST_FOREACH(::boost::tie(one, two), int2strMap) { std::cout << one << two << std::endl; } However, this fails to compile, and gives me the

Overriding memory allocator in MSVC++

南楼画角 提交于 2019-12-23 14:59:36
问题 While Microsoft standard runtime provides debugging version of allocation functions, it does not really work, because you are not supposed to use naked new in C++ code, so the instrumentation points to standard library, or nowhere because standard library can't be instrumented anyway. Now I have code that can produce (and record) backtraces of allocations and I also used DUMA. However attempts at replacing the allocation functions broke when we used streams, because streambuf calls to some

std::cout usage in constructors of objects with static storage duration

我的未来我决定 提交于 2019-12-23 12:55:59
问题 Is it safe to use std::cout in constructors of objects with statc storage duration in C++98 / C++03? It seems from this answer that it isn't but it doesn't include any quotes from the standard. Is it only safe to do that in C++11 and C++14? 回答1: From C++14 (N3797), §27.4p2: The objects are constructed and the associations are established at some time prior to or during the first time an object of class ios_base::Init is constructed, and in any case before the body of main begins exe- cution

Why old usage (c++03) of auto does not compile under C++11?

谁说胖子不能爱 提交于 2019-12-23 12:47:56
问题 I know that auto has a little usage before because it is the default for variables (opposite to static) - see question Consider however valid C++03 code where, maybe for self-explanatory, this keyword was used: auto int foo2 = 8; It compiles under C++03, and does not compile under C++11. Is there any reason for not being back-compatible with C++03? What was the source of standard committee opinion that this keyword was not used? Are there any statistics of keyword usage? BTW i tested with gcc

What is the equivalent of /proc/self/exe on Macintosh OS X Mavericks?

浪子不回头ぞ 提交于 2019-12-23 02:44:38
问题 I'm porting a Linux C++03 application to Darwin OS X and have some code that reads the symbolic link at /proc/self/exe to determine the directory in which the executable running is located. How can I compute the directory of the current executable running on Macintosh Darwin OS X Mavericks in C++? Here is my existing code that works on Linux: bool resolveBinaryLocation(string &binaryDirname) { // Read the symbolic link '/proc/self/exe'. const char *linkName = "/proc/self/exe"; const size_t

Ensure derived class constructor must call specific base class method

那年仲夏 提交于 2019-12-22 10:05:03
问题 In a C++(03) class, I have a member variable, which must be assigned a value during object construction. However, only the derived class can compute the required value. As discussed in this post Does C++ require you to initialize base class members from its derived class?, I understand that the derived class cannot initialize a base class member, but an assignment is sufficient for me. Hence, I provide a method in the base class to assign a value, but I cannot figure out how I can force the

What's the best way to return something like a collection of `std::auto_ptr`s in C++03?

℡╲_俬逩灬. 提交于 2019-12-22 04:48:13
问题 std::auto_ptr is not allowed to be stored in an STL container, such as std::vector . However, occasionally there are cases where I need to return a collection of polymorphic objects, and therefore I can't return a vector of objects (due to the slicing problem). I can use std::tr1::shared_ptr and stick those in the vector , but then I have to pay a high price of maintaining separate reference counts, and object that owns the actual memory (the container) no longer logically "owns" the objects

What was `auto` used for before?

百般思念 提交于 2019-12-22 04:39:22
问题 I know that before C++11 the auto keyword had a completely different meaning; it was a storage type specifier indicating an object that has automatic storage type (ie, placed on the stack). That's how the theory goes... How would you actually use this keyword (syntax), and why? Also, I haven't seen this keyword in actual code pre-C++11; when was it useful (what time period)? 回答1: It was used to declare a local variable with automatic storage duration (i.e., "on the stack"). At least since C90

How to compile Boost with an older std of C++? (C++03 in particular)

Deadly 提交于 2019-12-22 03:43:15
问题 I am working in a project dependent of Boost (http://kratos-wiki.cimne.upc.edu/index.php/Main_Page), this project currently only supports C++03. With the last update of gcc++ (v.5) the C++11 has become the default std, technically I solved the problem modifying the CXX_FLAGS adding: -std=c++03 The problem comes with the Boost library, which I am not able to compile with the C++03 std (I think, I don't know how to check with which std I have compiled). I tried employing the following command

Overriding new with debug version without damaging placement new

对着背影说爱祢 提交于 2019-12-21 12:36:09
问题 Microsoft runtime library provides debug version of allocation functions. For C++ this is a debug variant of operator new with the signature: void *operator new(size_t size, int blockType, const char *filename, int linenumber); and a macro is defined like #define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__) Now to instrument all allocations, one normally defines #if defined DEBUG_NEW #define new DEBUG_NEW #endif However this definition breaks any place that uses placement new, because the