c++03

C++, is set_terminate local to every thread?

妖精的绣舞 提交于 2019-12-09 05:37:42
问题 Should set_terminate / get_terminate set a different terminate exception processor for several threads in C++ 2011 or C++ 2003? E.g. if I have program and sets terminate handler to func_1 ; then I start 3 threads. What are terminate handlers in new threads? What if in every thread I will set terminate handler to func_2 in first thread, func_3 in second thread and so on. N3242 (C++ 2011 draft) says nothing about it in [handler.functions] or in [support.exception] / [exception.terminate] PS:

Why doesn't PRIu64 work in this code?

百般思念 提交于 2019-12-09 02:27:54
问题 As per this answer, I tried printing a uint64_t , but it gives me an error: error: expected ``)' before 'PRIu64' Following is the minimal code showing what I am trying to do: #define __STDC_FORMAT_MACROS #include <inttypes.h> #include <cstdio> class X { X() { uint64_t foo = 0; printf("%07" PRIu64 ": ", foo); } }; int main() {} This minimal code compiles, but my actual code does not. However, I have tried with the 2 lines inside X::X() exactly the same in my actual code, and that does not work

Is it possible to get a string that would containing namespace and class name at compile time?

左心房为你撑大大i 提交于 2019-12-08 16:31:47
问题 I wonder how to define a macro that would for given class name output its namespace and class name in a format like: "Namespace.SubNamespace.ClassName"? So writting something like this: // MyClass.h #include <string> namespace NS { namespace SNS { class MyClass { static std::string str; }; } } //MyClass.cpp #include <MyClass.h> using namespace std; string NS::SNS::MyClass::str = SUPER_MACRO(/*params if needed yet none would be prefered*/); I want to get str to be "NS.SNS.MyClass". I would

Why isn't mySet.erase(it++) undefined behavior, or is it?

别说谁变了你拦得住时间么 提交于 2019-12-08 15:39:05
问题 Accordint to this quite highly upvoted answer, the canonical way to iterate through a set erasing some elements is the following: for (it = mySet.begin(); it != mySet.end(); ) { if (conditionToDelete(*it)) { mySet.erase(it++); } else { ++it; } } This, of course, is a result of C++03's set erase not returning an iterator. Otherwise one could write it = mySet.erase(it); It is also obvious that one can write itToDelete = it++; mySet.erase(itToDelete); This question is not about how to delete

Is value initialization part of the C++98 standard? If not, why was it added in the C++03 standard?

断了今生、忘了曾经 提交于 2019-12-08 15:15:14
问题 Cheers and hth. - Alf made a comment in this answer that value initialization is arguably a new feature of C++03 compared to C++98. I wonder what he meant. Is value initialization part of C++98? Is it present in concept but not in name? Why was it added to the C++03 standard? I have a copy of the '03 standard but not the '98 standard. Here's the definition of default initialization and value initialization. To default-initialize an object of type T means: — if T is a non-POD class type

Are members of a POD-struct or standard layout type guaranteed to be aligned according to their alignment requirements?

馋奶兔 提交于 2019-12-08 15:02:45
问题 Given a POD-struct (in C++03) or a standard layout type (in C++11), with all members having a fundamental alignment requirement, is it true that every member is guaranteed to be aligned according to its alignment requirement? In other words, for all members m_k in { m0 ... mn } of standard layout type S , struct S { T0 m0; T1 m1; ... TN mn; }; is the following expression guaranteed to evaluate to true ? (offsetof(S,m_k) % alignof(decltype(S::m_k))) == 0 Please give answers for both C++03 and

Static local variable initialisation in multithreaded environment

∥☆過路亽.° 提交于 2019-12-08 14:39:42
问题 Suppose there is a function (member function possibly) SomeType foo() { static SomeType var = generateVar(); return var; } How var will be initialised if foo will be called 'for first time' from multiple threads simultaneously? Is it guaranteed that generateVar() will be called only once in any scenario (if used of course)? Is it guaranteed that foo will return the same value when called multiple times in any scenario? Is there a difference in behaviour for primitive or non-primitive types?

Share std::fstream or std::stringstream trough std::iostream

落爺英雄遲暮 提交于 2019-12-08 02:44:06
问题 I have a function that creates std::stringstream or std::fstream depending on condition, like: // Some class, stringStream_ and fileStream_ are members // obj.Stream() returns std::iostream& if (condition) { stringStream_.str(std::string()); obj->Stream().rdbuf(stringStream.rdbuf()); } else { boost::filesystem::path temp = boost::filesystem::unique_path(); fileStream_.open(temp.native().c_str(), std::ios_base::trunc | std::ios_base::in | std::ios_base::out); obj->Stream().rdbuf(fileStream_

C++ std:.auto_ptr or std::unique_ptr (to support multiple compilers, even old C++03 compilers)?

ε祈祈猫儿з 提交于 2019-12-07 22:10:42
问题 I'm trying to update some C++ code, I'd like to move toward a more modern code (c++11), but I still need to compile the code with some older compilers (c++03 compliant), because of supported platform constraints. I know in C++11 compilers std::auto_ptr is deprecated, but because of the older compiler support, I can't just replace them with std::unique_ptr. Is there a good practice to handle this "old compiler support, but start to move to C++11"? 回答1: As you noted, std::auto_ptr<> has been

Compile-time error for non-instantiated template members instead of link-time error

▼魔方 西西 提交于 2019-12-07 15:42:43
问题 I have template class ItemContainer that actually is facade for a whole family of containers with different capabilities like sorting, indexing, grouping etc. Implementation details are hidden in cpp. file using pimpl idiom and explicit instantiation. Template is instantiated only with well-known limited set of implementation classes that define the actual behavior of container. Main template implements common functions supported by all containers - IsEmpty() , GetCount() , Clear() etc. Each