c++-standard-library

Why does the C++ standard allow std::max_align_t and __STDCPP_DEFAULT_NEW_ALIGNMENT__ to be inconsistent?

倾然丶 夕夏残阳落幕 提交于 2021-02-18 11:54:56
问题 In Visual Studio, when compiling 64-bit: sizeof(std::max_align_t) is 8 __STDCPP_DEFAULT_NEW_ALIGNMENT__ is 16 So although std::max_align_t indicates that implementations of new should return pointers aligned to a multiple of 8 bytes, allocations with an alignment requirement of 16 bytes don't call the void* operator new (std::size_t count, std::align_val_t); method but call void* operator new (std::size_t count); (see https://en.cppreference.com/w/cpp/memory/new/operator_new) and expect them

C2676: binary '<': 'const _Ty' does not define this operator or a conversion to a type acceptable to the predefined operator

佐手、 提交于 2021-02-17 03:00:51
问题 I keep getting this error for the code below. Upon reading this, I believed my error to be the it++ in my for loop, which I tried replacing with next(it, 1) but it didn't solve my problem. My question is, is the iterator the one giving me the issue here? #include <iostream> #include <vector> #include <stack> #include <set> using namespace std; struct Node { char vertex; set<char> adjacent; }; class Graph { public: Graph() {}; ~Graph() {}; void addEdge(char a, char b) { Node newV; set<char>

Templated multistack implementation - how?

烈酒焚心 提交于 2021-02-11 15:48:34
问题 I need a 'MultiStack' taking different types of objects, putting each type in a separate stack. This is what it looks like so far. The open problem is: how to handle the containers for a number of different T class MultiStack { public: template<typename T> const T& Get() { return Container<T>.back(); } template<typename T> void Push( const T& t ) { Container<T>.push_back( t ); } template<typename T> void Pop( const T& /*t*/ ) { Container<T>.pop_back(); } private: // this does not make sense,

Templated multistack implementation - how?

。_饼干妹妹 提交于 2021-02-11 15:47:23
问题 I need a 'MultiStack' taking different types of objects, putting each type in a separate stack. This is what it looks like so far. The open problem is: how to handle the containers for a number of different T class MultiStack { public: template<typename T> const T& Get() { return Container<T>.back(); } template<typename T> void Push( const T& t ) { Container<T>.push_back( t ); } template<typename T> void Pop( const T& /*t*/ ) { Container<T>.pop_back(); } private: // this does not make sense,

Violating the one definition rule by simply linking dynamically

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-11 08:09:14
问题 Question: Are dynamically linked C++ programs on ELF platforms always on the brink of producing undefined behavior by violating the one definition rule? More specific: By simply writing a shared library exposing one function #include <string> int __attribute__((visibility("default"))) combined_length(const char *s, const char *t) { const std::string t1(t); const std::string u(s + t1); return u.length(); } and compiling it with GCC 7.3.0 via $ g++ -Wall -g -fPIC -shared \ -fvisibility=hidden

Violating the one definition rule by simply linking dynamically

孤者浪人 提交于 2021-02-11 08:08:04
问题 Question: Are dynamically linked C++ programs on ELF platforms always on the brink of producing undefined behavior by violating the one definition rule? More specific: By simply writing a shared library exposing one function #include <string> int __attribute__((visibility("default"))) combined_length(const char *s, const char *t) { const std::string t1(t); const std::string u(s + t1); return u.length(); } and compiling it with GCC 7.3.0 via $ g++ -Wall -g -fPIC -shared \ -fvisibility=hidden

Violating the one definition rule by simply linking dynamically

痞子三分冷 提交于 2021-02-11 08:07:37
问题 Question: Are dynamically linked C++ programs on ELF platforms always on the brink of producing undefined behavior by violating the one definition rule? More specific: By simply writing a shared library exposing one function #include <string> int __attribute__((visibility("default"))) combined_length(const char *s, const char *t) { const std::string t1(t); const std::string u(s + t1); return u.length(); } and compiling it with GCC 7.3.0 via $ g++ -Wall -g -fPIC -shared \ -fvisibility=hidden

Violating the one definition rule by simply linking dynamically

孤人 提交于 2021-02-11 08:07:28
问题 Question: Are dynamically linked C++ programs on ELF platforms always on the brink of producing undefined behavior by violating the one definition rule? More specific: By simply writing a shared library exposing one function #include <string> int __attribute__((visibility("default"))) combined_length(const char *s, const char *t) { const std::string t1(t); const std::string u(s + t1); return u.length(); } and compiling it with GCC 7.3.0 via $ g++ -Wall -g -fPIC -shared \ -fvisibility=hidden

Violating the one definition rule by simply linking dynamically

不打扰是莪最后的温柔 提交于 2021-02-11 08:06:55
问题 Question: Are dynamically linked C++ programs on ELF platforms always on the brink of producing undefined behavior by violating the one definition rule? More specific: By simply writing a shared library exposing one function #include <string> int __attribute__((visibility("default"))) combined_length(const char *s, const char *t) { const std::string t1(t); const std::string u(s + t1); return u.length(); } and compiling it with GCC 7.3.0 via $ g++ -Wall -g -fPIC -shared \ -fvisibility=hidden

Error C2676: std::set::const_iterator doesn't have operator+ function?

断了今生、忘了曾经 提交于 2021-02-10 20:09:42
问题 std::set<int> s = { 1,2,3,4,5 }; std::set<int> s2(s.begin(), s.begin() + 2); I want to assgin several values of s into s2 . But got below compile error: Error C2676 binary ' + ': ' std::_Tree_const_iterator<std::_Tree_val<std::_Tree_simple_types<_Ty>>> ' does not define this operator or a conversion to a type acceptable to the predefined It seems std::set::const_iterator doesn't have operator+ method. 回答1: It seems std::set::const_iterator doesn't have operator+ method. You are right about