c++98

How to recompile source file every time while using cmake 2.8.2 in single build for c++11 and c++98 for shared library creation?

与世无争的帅哥 提交于 2019-12-01 14:39:51
I have a project directory structure of: Root Source Common MyFolder ++ My 3 source files and header When I am building my project it generates 3 to 4 shared libraries. Lib1 compiled using c++98 and others using c++11. Flags are added in CmakeList.txt which is at root. I need my 3 source files to be compiled for Lib1 and for other Libs as as well. but here what happens is compiler is first compiling my source file for lib using c++11 and then it is trying to use same .o file for Lib1 as well. So for .o file which is generated using c++11 is throwing exception when same is used for c++98

port string interpolation from c++14 to c++98

核能气质少年 提交于 2019-12-01 14:19:07
I'm trying to port this answer: Replace N formulas to one (string interpolation) to a standard c++98 implementation. C++14 version: #include <algorithm> #include <iostream> #include <iterator> #include <map> #include <string> using namespace std; int main() { map<string, string> interpolate = { { "F"s, "a && b && c"s }, { "H"s, "p ^ 2 + w"s }, { "K"s, "H > 10 || e < 5"s }, { "J"s, "F && !K"s } }; for(const auto& i : interpolate) for_each(begin(interpolate), end(interpolate), [&](auto& it){ for(auto pos = it.second.find(i.first); pos != string::npos; pos = it.second.find(i.first, pos)) it

How to recompile source file every time while using cmake 2.8.2 in single build for c++11 and c++98 for shared library creation?

混江龙づ霸主 提交于 2019-12-01 12:28:16
问题 I have a project directory structure of: Root Source Common MyFolder ++ My 3 source files and header When I am building my project it generates 3 to 4 shared libraries. Lib1 compiled using c++98 and others using c++11. Flags are added in CmakeList.txt which is at root. I need my 3 source files to be compiled for Lib1 and for other Libs as as well. but here what happens is compiler is first compiling my source file for lib using c++11 and then it is trying to use same .o file for Lib1 as well.

Infer template argument from default parameter

£可爱£侵袭症+ 提交于 2019-12-01 04:12:54
问题 Consider this code: #include <functional> template <typename T,typename COMP> bool foo(T a,T b,COMP c = std::less<T>()) { return c(a,b); } bool bar(int a, int b){ return a<b;} int main(){ foo(1,2,bar); // OK foo(1,2,std::less<int>()); // OK foo(1,2); // error } The first two calls are fine, but it seems to be forbidden to let the compiler infer the type of COMP from the default parameter: <source>:14:5: error: no matching function for call to 'foo' foo(1,2); ^~~ <source>:4:6: note: candidate

Behavior of self-assignment with const ref parameter

早过忘川 提交于 2019-12-01 03:56:11
I stumbled upon some very old code which has a class with a defined copy assignment operator which takes its parameter as a const reference, but also does not check for self-assignment, so essentially: struct A { int q; A(): q(3) {} A& operator=(const A& a) { q = a.q; return *this; } }; What is the behavior of this assignment operator when an instance of A is assigned to itself? I would assume this causes problems as it "breaks" the constness of the paramater, any compiler could assume that the parameter is not changed and optimize based on this. However neither clang nor gcc emit a warning,

Mixing different C++ standards with GCC

梦想的初衷 提交于 2019-11-30 03:51:37
问题 I have the following scenario: There are two components one is written in C++11 the other in C++98. Both are compiled from scratch using the same GCC 4.9. One uses the implicit default --std=gnu++98 the other explicitly sets --std=c++11 . Even after doing some research I could not completely answer the question if this could cause issues. The GCC wiki says: The C++98 language is ABI-compatible with the C++11 language, but several places in the library break compatibility. This makes it

Using boost::assign::list_of

无人久伴 提交于 2019-11-29 06:10:38
This compiles: std::vector<int> value = boost::assign::list_of(1)(2); But not this: Constructor(std::vector<int> value) { } Constructor (boost::assign::list_of(1)(2)); Is there a one-liner solution for initializing the vector passed to the constructor? Better still, if the constructor copies to a class variable by taking a reference instead: Constructor(std::vector<int>& value) { _value = value; } UPDATE If I try the following: enum Foo { FOO_ONE, FOO_TWO }; class Constructor { public: Constructor(const std::vector<Foo>& value){} }; Constructor c(std::vector<Foo>(boost::assign::list_of(FOO_ONE

“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

Time complexity of removing items in vectors and deque

烂漫一生 提交于 2019-11-29 01:34:59
I have read that time complexity of adding items to end of a std::vector is amortized constant and inserting items at the top and bottom of a std::deque is constant.Since both these containers have a random access iterator thus accessing elements at any index is constant. Please let me know if I have any of these facts wrong.My question is if accessing an element in a std::vector or std::deque is constant then why is the time complexity of removing an element via erase O(n). One of the answers here here states that removing elements via erase is O(n). I know that erase removes the elements

C++11 Exception's destructor allows to throw now?

懵懂的女人 提交于 2019-11-28 13:20:15
any idea why virtual ~exception() throw() is in C++98, but virtual ~exception() is in C++11? What's the design decision that allows C++11 to throw in the destructor of the class exception ? From here : c++98: class exception { public: exception () throw(); exception (const exception&) throw(); exception& operator= (const exception&) throw(); virtual ~exception() throw(); virtual const char* what() const throw(); } c++11: class exception { public: exception () noexcept; exception (const exception&) noexcept; exception& operator= (const exception&) noexcept; virtual ~exception(); virtual const