tr1

tr1::unordered_set union and intersection

China☆狼群 提交于 2019-11-26 23:12:54
问题 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. 回答1: I see that set

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

坚强是说给别人听的谎言 提交于 2019-11-26 15:19:49
问题 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 ? 回答1: shared_ptr must manage a reference counter and the carrying of a deleter functor that is deduced by the type of

Why is std::function not equality comparable?

那年仲夏 提交于 2019-11-26 14:36:17
This question also applies to boost::function and std::tr1::function . std::function is not equality comparable: #include <functional> void foo() { } int main() { std::function<void()> f(foo), g(foo); bool are_equal(f == g); // Error: f and g are not equality comparable } In C++11, the operator== and operator!= overloads just don't exist. In an early C++11 draft, the overloads were declared as deleted with the comment (N3092 §20.8.14.2): // deleted overloads close possible hole in the type system It does not say what the "possible hole in the type system" is. In TR1 and Boost, the overloads

Why is std::function not equality comparable?

喜你入骨 提交于 2019-11-26 03:57:30
问题 This question also applies to boost::function and std::tr1::function . std::function is not equality comparable: #include <functional> void foo() { } int main() { std::function<void()> f(foo), g(foo); bool are_equal(f == g); // Error: f and g are not equality comparable } In C++11, the operator== and operator!= overloads just don\'t exist. In an early C++11 draft, the overloads were declared as deleted with the comment (N3092 §20.8.14.2): // deleted overloads close possible hole in the type

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

非 Y 不嫁゛ 提交于 2019-11-26 01:27:35
问题 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: class Foo { public: void doSomething() {} void bindFunction() { // ERROR std::function<void(void)> f = &Foo::doSomething; } }; I receive error C2064: term does not evaluate to a function taking 0 arguments in xxcallobj combined with some weird template instantiation errors. Currently I am working on Windows 8

What is the usefulness of `enable_shared_from_this`?

主宰稳场 提交于 2019-11-26 00:26:44
问题 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. 回答1: It enables you to get a valid shared_ptr instance to this , when all you have is this . Without it, you would have no way of getting a shared_ptr to this , unless you already had one as a member. This example from the boost