c++98

C++ boost asynchronous timer to run in parallel with program

匆匆过客 提交于 2021-02-04 06:28:48
问题 Note: This is for C++98 I am trying to develop a simple timer/counter that runs in the background of my main program. I haven't used asynchronous timers before, and I have been trying to follow the boost tutorials on how to do this, but they still seem to block my main function. I've slightly modified Timer.3 from the boost website to experiment. Essentially, with the program below what I want to do is: Run main Execute testRun() which counts to 5 At the same time testRun() is counting, print

Alternative to using namespace as template parameter

假如想象 提交于 2021-01-27 06:30:46
问题 I know I cannot use a namespace as a template parameter. However, I'm trying to achieve behavior similar to this: template <typename T> void foo(T::X* x) { T::bar(x); } Except T is a namespace rather than a struct or a class. What is the best way to achieve the most similar result to what I am expecting? 回答1: Except T is a namespace rather than a struct or a class. What is the best way to achieve the most similar result to what I am expecting? Don't mention T at all. template <typename X>

Do c++ guarantee header-initialized static const member to share a single instance across compile units and libraries?

萝らか妹 提交于 2020-06-16 09:51:02
问题 Let's consider a code header: class uid { public: uid () {++i; } static int i; }; class foo { public: const static uid id; } source: static int uid::i = 0; The header could be included into several source files, shared between compiler units and libraries. Is it guaranteed that there would be only one instance off foo::id , that foo::id::id() would be called once at run-time and, the most important thing, would foo::id.i be the same everywhere in the program and it's libraries? On the other

pthread is not starting for class instance

白昼怎懂夜的黑 提交于 2020-05-24 04:04:56
问题 NOTE: C++98 Hi, I'm a little new to c++ and I am writing a databaes program and am attempting to start a timer using the boost::asio package using pthread. The aim of the timer is to start after sql queries have been placed inside a buffer, of which will run an execute function if nothing has been received for a period of time. I have managed to get it to compile, but it doesn't look like the pthread instance is starting. I have called the pthread inside my getInstance method, and the boost:

Time-of-Check, Time-of-Use issues involving access(), faccessat(), stat(), lstat(), fstat(), open(), and fopen()

孤者浪人 提交于 2020-01-25 02:56:05
问题 I don't post here often, so bear with me while I try to decide how to solve this problem. I'm updating a code base that hasn't been touched for between 10 - 20 years. The code was written without adherence to best practices, and by many authors with sometimes incomplete understandings of security conventions, or perhaps even before those conventions were common practice. The compiler used on this code is c++98 or c++03, but not more recent. The code is also cross platform between Linux and

Using pointer conversions to store/cast values: Am I breaking the strict aliasing rule?

时间秒杀一切 提交于 2020-01-09 11:42:28
问题 The question relates to this post. Some authoritative users stated that the following code breaks strict aliasing rules. #include <boost/static_assert.hpp> template <typename T> struct MyType { private: T data; public: template <typename U> operator U () { BOOST_STATIC_ASSERT_MSG(sizeof(U) == sizeof(T),"Trying to convert to data type of different size"); return *((U*) &data); } template <typename U> NeonVectorType<T>& operator =(const U& in) { BOOST_STATIC_ASSERT_MSG(sizeof(U) == sizeof(T),

Vector of const objects giving compile error

核能气质少年 提交于 2020-01-08 21:45:09
问题 I have declared the following in my code vector <const A> mylist; I get the following compile error - new_allocator.h:75: error: `const _Tp* __gnu_cxx::new_allocator<_Tp>::address(const _Tp&) const \[with _Tp = const A]' and `_Tp* __gnu_cxx::new_allocator<_Tp>::address(_Tp&) const [with _Tp = const A]' cannot be overloaded But if declare - vector <A> mylist; my code compiles. Is const not allowed in this context? I am copying my code here for everyone'e reference - #include <iostream>

Does std::vector::resize() ever reallocate when new size is smaller than current size? [duplicate]

给你一囗甜甜゛ 提交于 2020-01-03 07:25:08
问题 This question already has answers here : Closed 6 years ago . Possible Duplicate: std::vector resize downward If I resize() an std::vector to some size smaller than its current size, is it possible that the vector will ever allocate new memory? This is important to me for performance reasons. 回答1: No, resize ing to a smaller size will never reallocate. In case the container shrinks, all iterators, pointers and references to elements that have not been removed remain valid after the resize and

Legal legacy code using pointers suddenly becomes UB

落爺英雄遲暮 提交于 2020-01-02 08:39:06
问题 Let's say we have this legacy code from C++98: bool expensiveCheck(); struct Foo; bool someFunc() { Foo *ptr = 0; if( expensiveCheck() ) ptr = new Foo; // doing something irrelevant here ... if( ptr ) { // using foo } delete ptr; return ptr; // here we have UB(Undefined Behavior) in C++11 } So basically pointer here is used to keep dynamically allocated data and use it as a flag at the same time. For me it is readable code and I believe it is legal C++98 code. Now according to this questions:

What is “ANSI C++”?

会有一股神秘感。 提交于 2020-01-01 08:37:30
问题 I've had someone tell me that C++98 was written under ANSI before being formally standardised as ISO/IEC 14882:1998. I know that ANSI was involved with C, but I can't seem to find much in the way of proof that the phrase "ANSI C++" is terribly accurate. Is "ANSI C++" a good description for C++98? Is "ANSI C++" a good description for subsequent versions of the C++ standard? 回答1: Initially, in '89, the standardization of C++ was handled by ANSI X3J16. Starting in '91 ISO WG21 joined in. You may