tr1

tr1::unordered_set union and intersection

不问归期 提交于 2019-11-27 22:46:24
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 provide the function for intersection, union, difference.. Since that's the basic operation of sets. Of course I can write a function by myself, but I just wonder if there are built in function from tr1. Thank you very much. j_random_hacker I see that set_intersection() et al. from the algorithm header won't work as they explicitly require their inputs

How is tr1::reference_wrapper useful?

浪尽此生 提交于 2019-11-27 21:15:58
问题 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? 回答1: It's like boost::ref, as far as I know. Basically, a reference which can be copied. Very useful when binding to functions where you need to pass parameters by reference. For example

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

天涯浪子 提交于 2019-11-27 20:03:00
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 ) boost::bind ( completely separate library ) or std::shared_ptr , std::tr1::shared_ptr , and boost::shared_ptr , ...etc Update bind , shared_ptr are examples that help to clarify my question. My intention was to understand the general differences between those three namespaces. There are several libraries that exist in all three namespaces, and

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

*爱你&永不变心* 提交于 2019-11-27 17:31:39
问题 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's implementation as well? For boost::hash , it's enough to provide a free function size_t hash_value (const MyType&) , is there something similar for the TR1 implementation? 回答1: Yes, this will also

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

前提是你 提交于 2019-11-27 10:48:18
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 list? (Btw, I've already googled, but I can't find anything reliable.) Are there any pitfalls for using the std::tr1::shared_ptr ? Emilio Garavaglia shared_ptr must manage a reference counter and the carrying of a deleter functor that is deduced by the type of the object given at initialization. The shared_ptr class typically hosts two members: a T

Is std::array<T, S> guaranteed to be POD if T is POD?

时光怂恿深爱的人放手 提交于 2019-11-27 07:35:30
问题 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. MyMem.Read>(SomeAddress); (This doesn't actually read out a C++ string, it reads out a C-style string and converts it to a C++ string.) Vector types. e.g. MyMem.Read>(SomeAddress, NumElem); (This doesn't actually read out a vector, rather it reads out a C-style array

C++ TR1: how to use the normal_distribution?

我是研究僧i 提交于 2019-11-27 06:47:40
问题 I'm trying to use the C++ STD TechnicalReport1 extensions to generate numbers following a normal distribution, but this code (adapted from this article): mt19937 eng; eng.seed(SEED); normal_distribution<double> dist; // XXX if I use the one below it exits the for loop // uniform_int<int> dist(1, 52); for (unsigned int i = 0; i < 1000; ++i) { cout << "Generating " << i << "-th value" << endl; cout << dist(eng) << endl; } only prints 1 "Generating..." log message, then never exits the for loop

How does weak_ptr work?

纵然是瞬间 提交于 2019-11-27 06:27:02
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 understand all the things it uses. Thanks. Paul Groke shared_ptr uses an extra "counter" object (aka. "shared count" or "control block") to store the reference count. (BTW: that "counter" object also stores the deleter.) Every shared_ptr and weak_ptr contains a pointer to the actual pointee, and a second pointer to the "counter" object. To

Comparing std::function<>

喜夏-厌秋 提交于 2019-11-27 06:20:10
问题 Is it possible to somehow compare two std::tr1::function<> objects? What if I have a collection of function<void(int,float)> objects and want to add and remove event handlers? Adding is trivial, but finding the one to be removed seems to be impossible. 回答1: Based on information from Stack Overflow at the following link, it IS possible but only if you wrap the std::function object in its own class. std::vector of std::function By using a wrapper class, you can test whether two wrapped std:

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

孤人 提交于 2019-11-27 04:24:44
问题 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 ) boost::bind ( completely separate library ) or std::shared_ptr , std::tr1::shared_ptr , and boost::shared_ptr , ...etc Update bind , shared_ptr are examples that help to clarify my question. My intention was to understand the general differences