c++98

Using SFINAE to detect a member function [duplicate]

ⅰ亾dé卋堺 提交于 2019-12-21 09:15:48
问题 This question already has answers here : Is it possible to write a template to check for a function's existence? (25 answers) Closed 6 years ago . In C++11, to find out whether a class has a member function size , you could define the following test helper: template <typename T> struct has_size_fn { typedef char (& yes)[1]; typedef char (& no)[2]; template <typename C> static yes check(decltype(&C::size)); template <typename> static no check(...); static bool const value = sizeof(check<T>(0))

g++ flag to only check syntax?

守給你的承諾、 提交于 2019-12-21 06:06:38
问题 Is there a way to have g++ check for C++98 syntax when compiling but at the same time compile as if no -std= has been given ? My goal is to make sure that my source code stays C++98 but I don't want to prevent g++ from using any newer optimisation or trick. For the moment, I compile my projet twice, once with CXXFLAGS=-std=c++98 and one with a final empty CXXFLAGS for release. It looks like gcc 5 will have -Wc90-c99-compat and -Wc99-c11-compat , that something in that direction. 回答1: You will

Can Lambda expression be downgraded to C++ 98

若如初见. 提交于 2019-12-20 02:57:38
问题 I recently got a problem need to integrate C++ 11 code written with lambda expression to old code base which only support C++ 98 compiler. I figured out couple of possible equivalences of lambda like Macro, functor or function pointer. But seems they are all limited when translating lambda with capture. For example a simple generic function with call back: template <class Fn> void ForEachObject(Fn fn) { for (uint i = 0; i < objectCount; i++) { fn(i, address + i * objectSize); } } and the

Iterate over a std::vector in sorted order [closed]

喜你入骨 提交于 2019-12-19 21:05:10
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . I receive from an API a vector of Foo as follows: std::vector<Foo> foos; I have then written a function called std::vector<std::string> getKeys(const std::vector<Foo>&) which iterates over the container and plucks out a key of type std::string for each Foo object. How would you iterate over the Foo objects in

Why does GCC allow use of round() in C++ even with the ansi and pedantic flags?

て烟熏妆下的殇ゞ 提交于 2019-12-19 18:56:40
问题 Is there a good reason why this program compiles under GCC even with the -ansi and -pedantic flags? #include <cmath> int main (int argc, char *argv []) { double x = 0.5; return static_cast<int>(round(x)); } This compiles clean (no warnings, even) with g++ -ansi -pedantic -Wall test.cpp -o test . I see two problems: round() shouldn't be available to C++ in ISO-conformant mode (since it comes from C99) Even if round() were available in this case, it should only be so from the std namespace Am I

Why does GCC allow use of round() in C++ even with the ansi and pedantic flags?

南笙酒味 提交于 2019-12-19 18:56:22
问题 Is there a good reason why this program compiles under GCC even with the -ansi and -pedantic flags? #include <cmath> int main (int argc, char *argv []) { double x = 0.5; return static_cast<int>(round(x)); } This compiles clean (no warnings, even) with g++ -ansi -pedantic -Wall test.cpp -o test . I see two problems: round() shouldn't be available to C++ in ISO-conformant mode (since it comes from C99) Even if round() were available in this case, it should only be so from the std namespace Am I

Is isnan in the std:: namespace? More in general, when is std:: necessary, optional or to be avoided?

↘锁芯ラ 提交于 2019-12-18 13:18:25
问题 With Mingw 4.7.2, I have a library that doesn't compile because of a call to isnan . The compiler says "everything will be fine" if I use std::isnan , and indeed I manage to compile my file. But if I check here ( Edit: but maybe I should have checked also here :-) ), the std:: doesn't seem to be necessary. If I add it, will the file be portable? More in general, for each case is there a general way to understand when putting std:: is necessary (for portability), optional or to be avoided?

What is the correct way to initialize static data members in C++ (98, 11 and 14)

瘦欲@ 提交于 2019-12-18 11:02:50
问题 What is the right way to initialize static data members in C++? I'm also interested in how it has changed from C++98, to C++11 to C++14. Here is an example: // bufferedOutput.h class BufferedOutput { // Static member declaration. static long bytecount; }; // bufferedOutput.cpp long BufferedOutput::bytecount = 50; Are there other ways to initialize static data members? 回答1: The rules have always been as follows: A const static data member (SDM) of integral or enumeration type can be

What is the correct way to initialize static data members in C++ (98, 11 and 14)

谁都会走 提交于 2019-12-18 11:02:46
问题 What is the right way to initialize static data members in C++? I'm also interested in how it has changed from C++98, to C++11 to C++14. Here is an example: // bufferedOutput.h class BufferedOutput { // Static member declaration. static long bytecount; }; // bufferedOutput.cpp long BufferedOutput::bytecount = 50; Are there other ways to initialize static data members? 回答1: The rules have always been as follows: A const static data member (SDM) of integral or enumeration type can be

How to easily create fully “variadic” functions with C++ 98 standard?

我怕爱的太早我们不能终老 提交于 2019-12-18 09:37:28
问题 The library https://github.com/c42f/tinyformat/blob/2f9335afd9941688e42d60cae5166b9f0600b2d1/tinyformat.h#L1104-L1116, uses this awesome trick to do "variadic" templates on C++ 98: inline void printfln(const char* fmt) { format(std::cout, fmt); std::cout << '\n'; } template<TINYFORMAT_ARGTYPES(n)> \ void printfln(const char* fmt, TINYFORMAT_VARARGS(n)) \ { \ format(std::cout, fmt, TINYFORMAT_PASSARGS(n)); \ std::cout << '\n'; \ } I am trying to improve it by eliminating the requirement to