tr1

C++ tr1 on GCC 3.4.4 (for the Nokia N810 tablet computer)

这一生的挚爱 提交于 2019-12-11 03:35:28
问题 What does it take to get C++ tr1 members (shared_ptr especially, but we'd like function and bind and ALL the others) working with GCC 3.4.4 (for the Nokia N810 tablet computer). Has anyone done this? Attempted this? It may not be feasible for us to upgrade to GCC 4.x to cross-compile for this device (but if you've done that, we'd love to know). There may be many approaches, and I'd like to avoid dead ends others have hit. We're trying to avoid bringing in boost, since it can be pretty

tr1::bind & pass by reference, is this behavior really expected?

十年热恋 提交于 2019-12-11 00:30:01
问题 Given the following test code #include <iostream> #include <tr1/functional> using namespace std; struct cl { cl(){ cout << " cl()\n"; } cl(const cl& from){ cout << " cl()[copy]\n"; } ~cl(){ cout << " ~cl()\n";} }; void f1(const cl& data){} void f2(const cl* pData){} int main(int c, char** a) { cout << "enter:\n"; cl data; cout << "ref:\n"; tr1::bind(&f1, data); cout << "ptr:\n"; tr1::bind(&f2, &data); cout << "exit:\n"; return 0; } I get the following output: $ g++ tr1BindDtorTest.cpp && ./a

confusion between std::[tr1::]ref and boost::ref

自作多情 提交于 2019-12-10 13:43:10
问题 Beware: This is GCC 4.1.2. We're on a proprietary embedded platform. We cannot update to a new compiler. So C++03 + TR1 it is. We somewhere have a function like this: template<typename T> void foo(const boost::any& x) { bar(boost::any_cast<T>(x)); } which is then later used in a bind expression: std::tr1::bind( &foo<T>, _1); This generates the following error: error: call of overloaded 'ref(const boost::any&)' is ambiguous note: candidates are: std::tr1::reference_wrapper<_Tp> std::tr1::ref(

Importing std::tr1 into std - is it legal? Does it improve portability?

房东的猫 提交于 2019-12-10 12:42:47
问题 I have C++03 code that looks like this: #include <boost/tr1/unordered_map.hpp> ... std::tr1::unordered_map<std::string, int> mystuff; ... I started to wonder that i would suffer later if/when i convert my code to C++11, which (i guess) doesn't have std::tr1::unordered_map but has std::unordered_map instead. So i came up with the following hack: namespace std { using namespace ::std::tr1; } ... std::unordered_map<std::string, int> mystuff; // no tr1 now! ... Is it legal (maybe importing stuff

Why some include files only reside in tr1?

三世轮回 提交于 2019-12-10 03:42:01
问题 When I try to include things like <unordered_map> it fails and says the file doesn't exist, while when I try to include <tr1/unordered_map> it works. however, the include files that are present also in c++03 are found, and are c++11 (like <vector> has move constructor). Also, headers that are only in c++11 and not in tr1 are found normally as well, like <thread> . Its like everything that was new in tr1 was just thrown into tr1 folder and everything else into normal include. Why is this

How to access target of std::tr1::shared_ptr in GDB

情到浓时终转凉″ 提交于 2019-12-09 16:55:19
问题 How can I access target of a std::tr1::shared_ptr in GDB. This doesn't work: (gdb) p sharedPtr->variableOfTarget If I try with the pointer object itself ( p sharedPtr ) I get something like this: $1 = std::tr1::shared_ptr (count 2) 0x13c2060 With a normal pointer I can do p *ptr and get all the data or p ptr->variable for just one variable. I'm on Centos 6.5, GCC 4.4.7-4.el6 and GDB 7.2-64.el6_5.2. 回答1: Try with (gdb) p (*sharedPtr.get()) that function returns the a pointer to the object

Effective C++ Notes(读书笔记)

限于喜欢 提交于 2019-12-09 12:05:57
1,视C++为一种语言联邦,大致分为4个部分: A)C。说到底C++仍是以C为基础。区块、语句、预处理器、内置数据类型、数组、指针等等统统来自C。 B)Object-Oriented C++。这部分也就是C with Classes所诉求的:classes(包括构造函数和虚构函数)、封装、继承、多态,虚函数等等。 C)Template C++。这是C++的范型编程部分,tamplates威力强大,它给我们带来了崭新的编程范型,也就是所谓的TMP模板元编程。 D)STL。STL是个template程序库,它对容器、迭代器、算法以及函数对象的规范有极佳的紧密配合与协调,然后template及程序库也可以其他想法建置出来。 2,尽量使用const,enum,inline代替#define A)#define不被视为语言的一部分,属于预处理指令,编译不会计入符号表无法调试。 B)#define在预处理器处理阶段只做简单的替换,这将带来很多预期意外的行为。如 #define MAX(a, b) ((a)>(b)?(a):(b)) 尽管上述宏定义已将变量用括号括起来了,但是还是不能避免MAX(++a, b+10)这样给a所带来的两次不是预期内的自增行为。以为替换为: template<typename T> inline T Max(const T& a, const T& b) {

C++: Assigning a function to a tr1::function object

≯℡__Kan透↙ 提交于 2019-12-08 02:22:01
问题 One of our classes provides tr1::function callback object. When I try assigning a member function to it, though, I get a compiler error. The examples below are untested and just to illustrate: Foo.h: class Foo() { public: Foo(); std::tr1::function<void (int x)> F; } Bar.h: class Bar() { public: Bar(); Foo* foo; void HookUpToFoo(); void Respond(int x); } Bar.cpp: Bar() { this->foo = new Foo(); this->HookUpToFoo(); } void Bar::HookUpToFoo() { this->foo->F = &Bar::Respond; // error } void Bar:

Replacing native VS 2010 (VC10) tr1 libraries with Boost.TR1

时光毁灭记忆、已成空白 提交于 2019-12-08 02:05:59
问题 I have been using VS 2005 (VC8) with Boost.TR1 in the std::tr1 namespace by setting the Include Directories of VS to prioritize the boost tr1 headers as described here. Now I am moving over to VS 2010 (VC10) and I seem to be getting compilation errors using the same include method. The Include Directories are set to: [boost-root]\boost\tr1\tr1 [boost-root] VC standard include directories Sample code: #include <functional> #include <iostream> int main(int argc, char ** argv) { std::cout << std

tr1::mem_fn and members with default arguments

只愿长相守 提交于 2019-12-07 08:20:36
问题 I have class with a member function that takes a default argument. struct Class { void member(int n = 0) {} }; By means of std::tr1::mem_fn I can invoke it: Class object; std::tr1::mem_fn(&Class::member)(object,10); That said, if I want to invoke the callable member on the object with the default argument, what's the correct syntax? std::tr1::mem_fn(&Class::member)(object); // This does not work g++ complains with the following error: test.cc:17: error: no match for call to ‘(std::tr1::_Mem