tr1

I don't understand std::tr1::unordered_map

I need an associative container that makes me index a certain object through a string, but that also keeps the order of insertion, so I can look for a specific object by its name or just iterate on it and retrieve objects in the same order I inserted them. I think this hybrid of linked list and hash map should do the job, but before I t...

Comparing std::tr1::function<> objects

I've been trying to implement a C#-like event system in C++ with the tr1 function templates used to store a function that handles the event. I created a vector so that multiple listeners can be attached to this event, i.e.: vector< function<void (int)> > listenerList; I'd like to be able to remove a handler from the list to stop a ...

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

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 ...

How is tr1::reference_wrapper useful?

Hi, recently I've been reading through Scott Meyers's excellent Effective C++ book. In one of the last tips he covered some of the features from TR1 - I knew many of them via Boost. However, there was one that I definitely did NOT recognize: tr1::reference_wrapper. How and when would I use tr1::reference_wrapper? ...

What is a good use case for tr1::result_of?

I hear that tr1::result_of gets used frequently inside of Boost... I'm wondering if there are any good (simple) use cases for tr1::result_of I can use at home. ...

Idiomatic use of std::auto_ptr or only use shared_ptr?

Now that shared_ptr is in tr1, what do you think should happen to the use of std::auto_ptr? They both have different use cases, but all use cases of auto_ptr can be solved with shared_ptr, too. Will you abandon auto_ptr or continue to use it in cases where you want to express explicitly that only one class has ownership at any given poin...

How do I use std::tr1::mem_fun in Visual Studio 2008 SP1?

The VS2008 SP1 documentation talks about std::tr1::mem_fun. So why, when I try and use std::tr1::mem_fun, why do I get this compile error?: 'mem_fun' : is not a member of 'std::tr1' At the same time, I can use std::tr1::function without problems. Here is the sample code I am trying to compile, which is supposed to call TakesInt on a...

tr1::mem_fn and members with default arguments...

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 corre...

tr1::mem_fn and tr1::bind: on const-correctness and overloading

What's wrong with the following snippet ? #include <tr1/functional> #include <functional> #include <iostream> using namespace std::tr1::placeholders; struct abc { typedef void result_type; void hello(int) { std::cout << __PRETTY_FUNCTION__ << std::endl; } void hello(int) const { std::cout << __PRETTY_FUNCTION__ <...

Is there a standard C++ function object for taking apart a std::pair?

Does anyone know if there's a de-facto standard (i.e., TR1 or Boost) C++ function object for accessing the elements of a std::pair? Twice in the past 24 hours I've wished I had something like the keys function for Perl hashes. For example, it would be nice to run std::transform on a std::map object and dump all the keys (or values) to ...

Are data structures an appropriate place for shared_ptr?

I'm in the process of implementing a binary tree in C++. Traditionally, I'd have a pointer to left and a pointer to right, but manual memory management typically ends in tears. Which leads me to my question... Are data structures an appropriate place to use shared_ptr? ...

TR1 Shared Arrays

I've had a hard time finding references in the TR1 documentation concerning shared arrays. The Boost documentation is fairly clear that there is a significant difference between the C++ "new" and "new[]" expressions. The shared_ptr template is meant to correctly hold a pointer to a dynamically allocated objected created using "new". T...

What version of GNU GCC supports the TR1 extern templates?

What is the earliest GNU GCC (g++) version to support the TR1 extern templates? For example, is it already supported in version 4.0? ...

returning a 'pointer' which is required to be held by a smart pointer

I have a project which I would like to make more use of smart pointers. Overall, I have been successful in this goal. However, I've come across one things which I'm not sure what the "best practice" is. Basically I would like to return a "pointer" from a function, but require that the user hold it in a smart pointer. Not only that, I do...

How to extend std::tr1::hash for custom types?

How do I allow the STL implementation to pick up my custom types? On MSVC, there is a class std::tr1::hash, which I can partially specialize by using namespace std { namespace tr1 { template <> struct hash<MyType> { ... }; } } but is this the recommended way? Moreover, does this work with GCC'...

C++0x, How do I expand a tuple into variadic template function arguments?

Consider the case of a templated function with variadic template arguments: template<typename Tret, typename... T> Tret func(const T&... t); Now, I have a tuple t of values. How do I call func() using the tuple values as arguments? I've read about the bind() function object, with call() function, and also the apply() function in diffe...

what is the usefulness of enable_shared_from_this

I ran across enable_shared_from_this while reading the Boost.Asio examples and after reading the documentation I am still lost for how this should correctly be used. Can someone please give me an example and/or and explanation of when using this class makes sense. ...

How to check for TR1 while compiling?

Dear all: We are programming a logging library that keeps itself in a .hpp file. We would like to include <tr1/unordered_map> (if the compiler supports TR1,) or the standard <map> otherwise. Is there a standard way of checking at compile time if tr1 is available or not? I was thinking that the same way that the "__cplusplus" define sym...

Hash function for a pair of long long?

I need to map a pair of long long to a double, but I'm not sure what hash function to use. Each pair may consist of any two numbers, although in practice they will usually be numbers between 0 and about 100 (but again, that's not guaranteed). Here is the tr1::unordered_map documentation. I started like this: typedef long long Int; type...

construct two shared_ptr objects from the same pointer

hello, I have a problem from "The C++ Standard Library Extensions": Exercise 6 I said in Section 2.4.2 that you shouldn't construct two shared_ptr objects from the same pointer. The danger is that both shared_ptr objects or their progeny will eventually try to delete the resource, and that usually leads to trouble. In...