tr1

TR1 Shared Arrays

淺唱寂寞╮ 提交于 2019-11-29 03:28:55
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". The shared_array template is meant to correctly hold a pointer to a dynamically allocated array using "new[]". I'm in the process of updating some code to use the TR1 shared_ptr template and associated functions, but I've found no mention of shared_array. Does the

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

人走茶凉 提交于 2019-11-29 03:03:11
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? Yes, this will also work for GCC. I'm using it in a bigger project and it works without problems. You could also provide your own

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

一世执手 提交于 2019-11-29 03:01:26
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? Yes, this will also work for GCC. I'm using it in a bigger project and it works without problems. You could also provide your own

enable_if method specialization

僤鯓⒐⒋嵵緔 提交于 2019-11-29 01:29:54
问题 template<typename T> struct A { A<T> operator%( const T& x); }; template<typename T> A<T> A<T>::operator%( const T& x ) { ... } How can I use enable_if to make the following specialization happen for any floating point type (is_floating_point)? template<> A<float> A<float>::operator%( const float& x ) { ... } EDIT: Here's an answer I came up which is different from the ones posted below... template<typename T> struct A { T x; A( const T& _x ) : x(_x) {} template<typename Q> typename std:

How is tr1::reference_wrapper useful?

强颜欢笑 提交于 2019-11-28 23:10:23
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? Nick 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 (using boost syntax): void Increment( int& iValue ) { iValue++; } int iVariable = 0; boost::function<

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

℡╲_俬逩灬. 提交于 2019-11-28 13:17:28
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 and converts it to a vector.) Overloads 2 and 3 are simply 'wrappers' around overload 1. (So if you're

Extracting a raw pointer from a shared_ptr

喜你入骨 提交于 2019-11-28 12:31:44
问题 Is it possible to extract a raw pointer from a std::shared_ptr or std::tr1::shared_ptr object? The intent is to tell the smart pointer object that I don't want it to manage the lifetime of the object anymore. The context is that I have an API that takes a raw pointer from users and does some processing on the object. To make things easier to manage API creates a shared_ptr out of this raw pointer. Now, the user might ask for the object to be returned. In that case, when giving the processed

C++ TR1: how to use the normal_distribution?

这一生的挚爱 提交于 2019-11-28 12:08:51
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 ! If I use the distribution I commented out instead, it terminates, so I'm wondering what I'm doing

Is TR2 Going to be Released in C++17?

試著忘記壹切 提交于 2019-11-28 04:41:54
问题 There is lots of sweet stuff in TR2. Is that going to be in C++17? I understand that TR1 was completed in 2005 and had to wait until C++11 to be standardized. But I also understand that TR2 is already complete? My link to C++17 doesn't mention anything about TR2, but I am hoping... 回答1: Maybe. The point of TR (and now technical specifications) is to allow something to mature independent of the standard iteration process. They can publish a TS, see how it works, see if there are any problems

Differences between different flavours of shared_ptr

烂漫一生 提交于 2019-11-28 02:37:55
问题 Are there any differences between boost::shared_ptr, std::tr1::shared_ptr and the upcoming (in C++0x ) std::shared_ptr ? Will porting from one to another have any overhead or are they basically the same? 回答1: According to the Boost website, the boost::shared_ptr ... ...conforms to the TR1 specification, with the only exception that it resides in namespace boost instead of std::tr1 . According to the Wikipedia C++0x page The TR1 implementation lacked certain pointer features such as aliasing