Questions tagged [tr1]

TR1 - C++ Technical Report 1, proposed extensions to the C++ standard library

The Technical Report on C++ Library Extensions (a.k.a ISO/IEC TR 19768) defined a number of new library components for C++, many taken from the Boost project. Nearly all the components in TR1 were included in the C++ 2011 standard.

232 questions
422
votes
6 answers

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 explanation of when using this class…
fido
  • 5,566
  • 5
  • 24
  • 20
246
votes
6 answers

Using generic std::function objects with member functions in one class

For one class I want to store some function pointers to member functions of the same class in one map storing std::function objects. But I fail right at the beginning with this code: #include class Foo { public: void…
Christian Ivicevic
  • 10,071
  • 7
  • 39
  • 74
77
votes
2 answers

How does weak_ptr work?

I understand how to use weak_ptr and shared_ptr. I understand how shared_ptr works, by counting the number of references in its object. How does weak_ptr work? I tried reading through the boost source code, and I'm not familiar enough with boost to…
Oliver Zheng
  • 7,831
  • 8
  • 53
  • 59
65
votes
7 answers

Why is std::function not equality comparable?

This question also applies to boost::function and std::tr1::function. std::function is not equality comparable: #include void foo() { } int main() { std::function f(foo), g(foo); bool are_equal(f == g); // Error: f and…
James McNellis
  • 348,265
  • 75
  • 913
  • 977
41
votes
4 answers

How is the std::tr1::shared_ptr implemented?

I've been thinking about using shared pointers, and I know how to implement one myself--Don't want to do it, so I'm trying std::tr1::shared_ptr,and I have couple of questions... How is the reference counting implemented? Does it use a doubly linked…
purepureluck
  • 1,271
  • 2
  • 14
  • 16
38
votes
4 answers

What are differences between std, tr1 and boost (as namespaces and/or libraries)?

I initially thought they're all the same, but it turned out to be wrong. So can anyone briefly explain the differences between these three? For example: std::bind ( newest one, next generation of C++ ) std::tr1::bind ( old, extension of C++ std…
roxrook
  • 13,511
  • 40
  • 107
  • 156
29
votes
6 answers

How does one include TR1?

Different compilers seem to have different ideas about TR1. G++ only seems to accept includes of the type: #include #include ... While Microsofts compiler only accept: #include #include…
Grumbel
  • 6,585
  • 6
  • 39
  • 50
26
votes
2 answers

Typedef a template class without specifying the template parameters

I'm trying to typedef either an unordered_map or std::map depending whether there are TR1 libraries available. But I don't want to specify the template parameters. From what i've read so far, typedef'ing templates without arguments is not possible…
Rollin_s
  • 1,983
  • 2
  • 18
  • 18
24
votes
3 answers

tr1::unordered_set union and intersection

How to do intersection and union for sets of the type tr1::unordered_set in c++? I can't find much reference about it. Any reference and code will be highly appreciated. Thank you very much. Update: I just guessed the tr1::unordered_set should…
Ross
  • 2,033
  • 4
  • 19
  • 19
22
votes
4 answers

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
Anteru
  • 19,042
  • 12
  • 77
  • 121
22
votes
3 answers

Is std::array guaranteed to be POD if T is POD?

I'm currently writing a C++ memory editing library and for the read/write APIs I use type traits (std::is_pod, std::is_same) and boost::enable_if to provide 3 overloads: POD types. e.g. MyMem.Read(SomeAddress); String types. e.g.…
RaptorFactor
  • 2,810
  • 1
  • 29
  • 36
22
votes
4 answers

Assigning existing values to smart-ptrs?

I am just learning about smart pointers, and I am having trouble assigning a pre-existing location of a variable to the standard library's shared pointer. For example, lets say you have an int x, which you do not know the value of. With normal…
bluepanda
  • 351
  • 1
  • 2
  • 7
21
votes
2 answers

How is tr1::reference_wrapper useful?

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:…
oz10
  • 153,307
  • 27
  • 93
  • 128
20
votes
11 answers

C++: Function wrapper that behaves just like the function itself

How can I write a wrapper that can wrap any function and can be called just like the function itself? The reason I need this: I want a Timer object that can wrap a function and behave just like the function itself, plus it logs the accumulated time…
Frank
  • 64,140
  • 93
  • 237
  • 324
19
votes
4 answers

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…
Frank
1
2 3
15 16