c++03

How to swap two __m128i variables in C++03 given its an opaque type and an array?

♀尐吖头ヾ 提交于 2019-12-30 10:38:08
问题 What is the best practice for swapping __m128i variables? The background is a compile error under Sun Studio 12.2, which is a C++03 compiler. __m128i is an opaque type used with MMX and SSE instructions, and its usually and unsigned long long[2] . C++03 does not provide the support for swapping arrays, and std:swap(__m128i a, __m128i b) fails under the compiler. Here are some related questions that don't quite hit the mark. They don't apply because std::vector is not available. How can we

Are there any cases where it is incorrect to replace push_back with emplace_back?

吃可爱长大的小学妹 提交于 2019-12-30 08:15:20
问题 Can I break a valid C++03 program by replacing std::vector::push_back with emplace_back and compiling it with C++ 11 compiler? From reading emplace_back reference I gather it shouldn't happen, but I'll admit I don't fully get rvalue references. 回答1: I constructed a short example that actually fails to compile when push_back is replaced by emplace_back : #include <vector> struct S { S(double) {} private: explicit S(int) {} }; int main() { std::vector<S>().push_back(0); // OK std::vector<S>()

How to test whether class B is derived from template family of classes

守給你的承諾、 提交于 2019-12-28 04:20:10
问题 How to test at compile time whether class B is derived from std::vector? template<class A> struct is_derived_from_vector { static const bool value = ????; }; How to test at compile time whether class B is derived from template family? template<class A, template< class > class Family> struct is_derived_from_template { static const bool value = ????; }; Using: template<class T> struct X {}; struct A : X<int> {} struct B : std::vector<char> {} struct D : X<D> {} int main() { std::cout << is

Why does this file stream, with no error flags set, fail to read unless I do tellg()?

半世苍凉 提交于 2019-12-25 09:09:58
问题 I have a fstream that seems to get into a phantom failure state, even though examining it (via conversion to bool ) reveals no error flags. Subsequent reads fail, which is unexpected. #include <fstream> #include <iostream> #include <cassert> int main() { const unsigned int SAMPLE_COUNT = 2; // Setup - create file with two "samples"; each sample has a double and a float { std::ofstream ofs("/tmp/ffs", std::ios::binary); const double colA[SAMPLE_COUNT] = { 1.0, 2.0 }; const float colB[SAMPLE

C++ Boost not found file

空扰寡人 提交于 2019-12-25 03:08:01
问题 I'm trying to use variant from boost and I'm receiving this error: fatal error C1083: Cannot open include file: 'boost/variant.hpp': No such file or directory I've included the files in project properties. In the Reference Directories and Library Directories I've tried also with "...\lib" "....\stage\lib" And also in the Include Directories I've tried also with: "...\boost_1_68_0" "...\boost_1_68_0\boost" In the beginning, I used D:\Libs\boost_1_68_0\libs and because it didn't work I've

How can I fake constructor inheritance in C++03?

纵饮孤独 提交于 2019-12-24 14:48:21
问题 As far as I know, you cannot inherit constructors in C++. But there are situations, where it might be required that it looks like you can instantiate inherited classes the same way you instantiate their base: struct Base { int i; int const j; Base(int i, int j) : i(i), j(j) {} }; // option 1) struct Derived1 : Base { Derived1(int i, int j) : Base(i,j) {} }; Base* baseFactory() { return new Derived1(42,47); } // option 2) struct Derived2 : Base { }; Base* baseFactory() { Base* b = new Derived2

Creating a word aligned char vector

戏子无情 提交于 2019-12-24 11:44:51
问题 I need to create a raw buffer data class, it has to return a pointer to char that is guaranteed to be word aligned. I was thinking about using a std::vector<<something>> vec . I know that most (if not all) implementations of std::vector will use operator new to allocate memory which is guaranteed to return maximally aligned memory but I don't want to rely on that. I don't want to create my own aligned allocator either. Seems like overkill. This is what I came up with: (lets pretend that

How to get Fully qualified domain name in unix

笑着哭i 提交于 2019-12-24 04:15:28
问题 Is there any function(C or C++) which returns FQDN(Fully qualified domain name) in UNIX platforms? 回答1: Use getifaddrs() to get the interfaces for the box in question, then use the "resolver interface" (man resolver) to query the FQDNs for the ip-addresses return by the former call to getifaddrs() . Do not use gethostname() or the command line tool hostname in this context, as an IXish box's "hostname" does not necessarily correlate with the FQDN's returned by a query issued for the box's

Does the address of the result of std::string::operator[] point to a writable, nul-terminated buffer?

雨燕双飞 提交于 2019-12-24 02:47:10
问题 I am modifying a function that accepts a const char* and uses a function, ProcessString. ProcessString is a function that expects a null-terminated character buffer as a char*. The characters in the buffer may or may not be modified, as defined by the function signature below. To "bridge the gap", I am using a temporary std::string: void ProcessString( char* str ); void SomeFunction( const char* str ) { string temp(str); ProcessString( &temp[0] ); } My primary question is about the guarantees

Detecting whether something is (boost) range with SFINAE

*爱你&永不变心* 提交于 2019-12-23 18:43:54
问题 For logging code, I would like to detect whether given argument to a template function can be iterated over using the tools from Boost.Range or not. Obviously I need to instantiate different code whether it is or not, so I need SFINAE, possibly (well, certainly) combined with boost::enable_if. I've tried detecting whether begin and end free functions are defined, like this: namespace is_range_impl { template <typename T> T &make(); struct any { template <class T> any(T const&); }; struct not