I have a function that uses Boost::move to move a lock - /** * Moving assignment operator transfers ownership of the lock */ const_iterator& operator=(const_iterator && other) { if (this != &other) { iter = other.iter; lock = boost::move(other.lock); } return *this; } I could get this code to compile using gcc 4.7.3 with -std=c++11 or -std=c++0x f
我有一个函数使用Boost :: move来移动一个锁 - /** * Moving assignment operator transfers ownership of the lock */ const_iterator& operator=(const_iterator && other) { if (this != &other) { iter = other.iter; lock = boost::move(other.lock); } return *this; } 我可以使用gcc 4.7.3和-std = c ++ 11或-std = c ++ 0x标志来获得此代码。 但是,对于gcc 4.6.4
Consider the following class: class Foo { private: void bar(const size_t); public: void foo(); }; now Foo::foo() should start threads executing bar , so this is how it's implemented: void Foo:foo() { auto handle = std::async(std::launch::async, &Foo::bar, this, 0); handle.get(); } This works flawlessly with g++-4.6.3, but not with g++-4.5.2, the error message
考虑以下课程: class Foo { private: void bar(const size_t); public: void foo(); }; 现在Foo::foo()应开始执行的线程bar ,所以这是它是如何实现的: void Foo:foo() { auto handle = std::async(std::launch::async, &Foo::bar, this, 0); handle.get(); } 这与g ++ - 4.6.3完美地工作,但不与g ++ - 4.5.2一起工作,错误信息是 include / c ++ / 4.5.2 / functional:180:9:错
I was just playing around with g++ 4.7 (one of the later snapshots) with -std=c++11 enabled. I tried to compile some of my existing code base and one case that failed somewhat confuses me. I would appreciate if someone can explain what is going on. Here's the code #include <utility> #include <iostream> #include <vector> #include <string> int main ( ) { std::
我只是在启用了-std = c ++ 11的情况下玩弄了g ++ 4.7(其中一个较晚的快照)。 我试图编译一些我现有的代码库和一个失败的混淆我的案例。 如果有人能解释发生了什么,我将不胜感激。 这是代码 #include <utility> #include <iostream> #include <vector> #include <string> int main ( ) { std::string s = "abc"; // 1 ok std::pair < std::string, int > a = std::make_pai
Code: #include <functional> struct Foo { virtual void mf() = 0; }; struct Bar: Foo { virtual void mf() {} }; int main() { Bar o; std::reference_wrapper<Foo const> wrapper( o ); } Result with MinGW g++ 4.6.1: [d:devtest] > g++ foo.cpp -std=c++0x [d:devtest] > _ Result with Visual C++ 10.0: [d:devtest] > cl foo.cpp foo.cpp C:Program Files (x86)Microsoft Visual
码: #include <functional> struct Foo { virtual void mf() = 0; }; struct Bar: Foo { virtual void mf() {} }; int main() { Bar o; std::reference_wrapper<Foo const> wrapper( o ); } 使用MinGW g ++ 4.6.1的结果: [d:devtest] > g++ foo.cpp -std=c++0x [d:devtest] > _ Visual C ++ 10.0的结果: [d:devtest] > cl foo.cpp foo.cpp C:Program Files (x86)Microsoft Visual Stud
I'm trying to use an associative_property_map to include index for vertices, but I get the following error with the following simple code, what is the problem ? #include <boost/graph/iteration_macros.hpp> #include <boost/graph/adjacency_list.hpp> using namespace std; using namespace boost; struct NodeData { int label; }; struct EdgeData { int age; }; typedef map<ve
我试图使用associative_property_map来包含顶点的索引,但是我用下面的简单代码得到以下错误,问题是什么? #include <boost/graph/iteration_macros.hpp> #include <boost/graph/adjacency_list.hpp> using namespace std; using namespace boost; struct NodeData { int label; }; struct EdgeData { int age; }; typedef map<vecS, size_t> IndexMap; IndexMap mapIndex; associative_property
I have a template class in C++ which takes as a char_type template parameter the character type, such as char , wchar_t , char32_t , etc... The class then use std::basic_string<char_type> in the code. Then somewhere in the class I fill a table of escaping sequences such as "&" . This does not work as depending on the template character type, we would need to use "
我在C ++中有一个模板类,它将char_type模板参数作为字符类型,例如char , wchar_t , char32_t等等。然后,类将在代码中使用std::basic_string<char_type> 。 然后,我在课堂上的某个地方填写一个转义序列表,如"&" 。 这不依赖于模板字符类型,我们需要使用"&" , L"&" , U"&" ... 有没有办法避免专门化模板函数来初始化表,例如使
I am using a lot of string functions like strncpy, strncat, sprintf etc. in my code. I know there are better alternatives to these, but I was handed over an old project, where these functions were used, so I have to stick with them for compatibility and consistency. My supervisor is very fussy about error checking and robustness, and insists that I check for buffer-overflow violations everytime
我在代码中使用了很多像strncpy,strncat,sprintf等字符串函数。 我知道有更好的替代方案,但是我交出了一个旧项目,在这些项目中使用了这些功能,所以为了兼容性和一致性,我必须坚持使用这些功能。 我的主管对错误检查和健壮性非常挑剔,并坚持每次使用这些函数时检查缓冲区溢出违规。 这在我的代码中创建了很多if-else语句,看起来不太漂亮。 我的问题是,每次我调用其中一个函数时,是否真的有必要检查溢出? 即使我知
I have never worked with #if , #ifdef , #ifndef , #else , #elif and #endif . As I was going through some source-codes, I found an extensive use of these directives. Did some reading on conditional-preprocessors but found no clue like how are they different from normal conditional statements . So I was wondering what is the advantage of following code: #include<iostream> int main() {
我从来没有使用#if , #ifdef , #ifndef , #else , #elif和#endif 。 当我通过一些源代码时,我发现了这些指令的广泛使用。 对条件预处理器进行了一些阅读,但没有发现像他们与常规条件语句不同的线索。 所以我想知道下面的代码有什么优势: #include<iostream> int main() { int i = 0; #if i == 0 std::cout<<"This"; #else std::cout<<"That"; #endif retu
I am using clock_gettime() in my C++ program to get the current time. However, the return value is seconds since epoch in UTC. This code can get messed up in my time zone during daylight savings when the time shifts by one hour. The system itself has NTP syncing it to always give the correct time in EST. Is there a way to get clock_gettime() to report the local time instead of UTC so I can a
我在我的C ++程序中使用clock_gettime()来获取当前时间。 但是,返回值是UTC以来的秒数。 如果时间偏移一个小时,此代码在夏令时期间可能会在我的时区中混乱。 系统本身具有NTP同步功能,以便始终在EST中提供正确的时间。 有没有办法让clock_gettime()报告本地时间而不是UTC,这样我可以避免夏令时问题? 意识到这个time也会报告自1970年以来的秒数(在time_t )。 如果你把timespec的tv_sec成员传给localtime或loca
For the purpose of a mini-scheduler inside my app I need to be able to schedule an event at some absolute local time. For instance, I may want to schedule it for 7 AM on November 5, 2017 . As anyone living in US probably knows, that is the night when the daylight saving ends at 2 AM . So I use the following method: //ERROR CHECKS ARE OMITTED FOR BREVITY HANDLE hTimer = ::CreateWaitableTimer
为了我的应用程序内的迷你调度程序的目的,我需要能够在某个绝对当地时间安排事件。 例如,我可能想要在November 5, 2017年November 5, 2017 7 AM安排它。 任何居住在美国的人都知道,那是夏令时在2 AM结束的那个夜晚。 所以我使用以下方法: //ERROR CHECKS ARE OMITTED FOR BREVITY HANDLE hTimer = ::CreateWaitableTimer(NULL, FALSE, NULL); //Nov 5, 2017 at 7:00 AM SYSTEMTIME stLocal = {2017, 11, 0, 5, 7, 0, 0