tr1

Is it worth using std::tr1 in production?

I'm using MS VC 2008 and for some projects Intel C++ compiler 11.0. Is it worth using tr1 features in production? Will they stay in new standard? For example, now I use stdext::hash_map. TR1 defines std::tr1::unordered_map. But in MS implementation unordered_map is just theirs stdext::hash_map, templatized in another way. ...

[C++] Index strings by other strings

Hello, I need to index specific strings with other strings and I can't really find a good way to do so. I tried to use tr1::unordered_map, but I'm having some difficulties using it. If someone could tell me what is the best way to do that I'd be really grateful :) I also need to index objects by a number (numbers are not in order so I ca...

Containers of reference_wrappers (comparison operators required?)

If you use stl containers together with reference_wrappers of POD types, code such as the following works just fine: int i = 0; std::vector< boost::reference_wrapper<int> > is; is.push_back(boost::ref(i)); std::cout << (std::find(is.begin(),is.end(),i)!=is.end()) << std::endl; However, if you use non-POD types like (contrived example)...

Type problem when including tuple

I'm using Visual Studio 2008 with Feature Pack 1. I have a typedef like this typedef std::tr1::tuple<std::string, std::string, int> tileInfo with a function like this const tileInfo& GetTile( int x, int y ) const. In the implementation file the function has the exact same signature (with the added class name qualifier) and I am gettin...

Random numbers from binomial distribution

I need to generate quickly lots of random numbers from binomial distributions for dramatically different trial sizes (most, however, will be small). I was hoping not to have to code an algorithm by hand (see, e.g., this related discussion from November), because I'm a novice programmer and don't like reinventing wheels. It appears Boost ...

On reference_wrapper and callable objects

Given the following callable object: struct callable : public std::unary_function <void, void> { void operator()() const { std::cout << "hello world" << std::endl; } }; a std::tr1::reference_wrapper<> calls through it: callable obj; std::tr1::ref(obj)(); Instead, when the operator() accepts an argument: s...

Are tr1 headers available for gcc v3.4.6?

Are tr1 headers available for g++ v3.4.6? If so, how can I locate them at compile time. The following is failing to compile: #include <tr1/memory> With the following error: myModule.h:20:24: tr1/memory: No such file or directory Do I need to move to a later compiler or do I have the headers somewhere? ...

Is there a sane default for std::tr1::function?

I spent some time googling but didn't really find anything. I want to be able to do this: std::tr1::function<void()> foo(SOME_DEFAULT_FUNCTION_THAT_DOES_NOTHING); // //Some code that could possibly assign foo // foo(); Otherwise I have to do this: std::tr1::function<void()> foo; // //Some code that could possibly assign foo // if(fo...

Difference between std::tr1::array and boost::array

I was under the impression that std::tr1::array was the same as the boost::array in that it would throw an exception when accessing an index out of bounds. In fact, I took a peek in the header and it appears that way as well. Could someone explain why the following code results in a bus error (gcc version 4.0.1 (Apple Inc. build 5465)) ...

difference between cstdint and tr1/cstdint

What is the difference between <cstdint> and <tr1/cstdint>? (apart from that one puts things in namespace std:: and the other in std::tr1::) Since this stuff isn't standard yet I guess it's compiler specific so I'm talking about gcc. To compile with the non-tr1 one I must compile with -std=c++0x, but there is no such restriction when us...

Portable way to use shared_ptr in GCC

GCC 4.1 uses the <tr1/memory> header and GCC 4.3 uses <memory> header, I need a portable way to use shared_ptr with GCC 4.3.2 and with GCC 4.2.1, is there any way to do that without checking GCC version macros or using external libraries like Boost ? ...

std::tr1::function and std::tr1::bind

I have a problem using a very complicated C function in a C++ class (rewriting the C function is not an option). C function: typedef void (*integrand) (unsigned ndim, const double* x, void* fdata, unsigned fdim, double* fval); // This one: int adapt_integrate(unsigned fdim, integrand f, void* fdata, ...

Problem with weak_ptr comparison in VS10

I can not get 'operator <' to compile for a weak_ptr using VS10. Am I missing an #include or #using? Even the the code sample in the documentation does not work for me. http://msdn.microsoft.com/en-us/library/bb982759.aspx // temp.cpp : Defines the entry point for the console application. // #include "stdafx.h" // std_tr1__memory__o...

On the initialization of std::array

Let's say you have a c++0x std::array member of a template class and you want to initialize it by means of a constructor that takes a couple of iterators: template <typename Tp, size_t N> class Test { public: template <typename Iterator> Test(Iterator first, Iterator last) { if (std::distance(first,last) > N ) ...

Crazy C++ Vector iterator

I declare: typedef std::tr1::shared_ptr<ClassA> SharedPtr; And then: std::vector<SharedPtr> mList; And: typedef std::vector<SharedPtr>::iterator ListIterator; The return of mList.size() is 0, but when I use iterators, it iterates over the vector which is empty ! This is how I use the iterator: for(ListIterator it = mList.begin(...

Looking for comprehensive TR1 documentation online

I really like the online STL documentation provided by http://www.cplusplus.com/. Separately, I use some of the TR1 extensions via their Boost implementations. I would like to find TR1 documentation online which is as good as the standard STL documentation provided by cplusplus.com. I'm especially interested in smart pointers and th...

std::tr1::mem_fn return type

I want to put the result of this: std::tr1::mem_fn(&ClassA::method); Inside a variable, what is the type of this variable ? That will look something like this: MagicalType fun = std::tr1::mem_fn(&ClassA::method); Also, what is the result type of std::tr1::bind ? Thank you ! ...

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

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]\boo...

TR1 from Boost or VC10 - Which one is better?

I'm currently migrating from Visual Studio 2008 to 2010. My software makes heavy use of Boost and it's TR1 features. I now get a lot of compiler errors, because VC10 has it's own TR1 implementation. I know I can disable Microsoft's TR1 implementation with the _HAS_CPP0X switch (see here), but I'm not sure if this also disables other fea...

.NET Interop and TR1 shared_ptr

How is it possible to marshal a shared_ptr from unmanaged C++ code into C#? I have a function in C++ (exposed through C bindings) that will allocate a new MyObject and return a pointer to it via a shared_ptr. In C++ I can call the function: MyObjHandle* ref = NULL: GetMyObject(&ref); // double ptr... where MyObjHandle is defined: ...