tr1

TR1 Shared Arrays

烂漫一生 提交于 2019-11-30 07:27:19
问题 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

Difference in performance between map and unordered_map in c++

筅森魡賤 提交于 2019-11-30 06:47:51
I have a simple requirement, i need a map of type . however i need fastest theoretically possible retrieval time. i used both map and the new proposed unordered_map from tr1 i found that at least while parsing a file and creating the map, by inserting an element at at time. map took only 2 minutes while unordered_map took 5 mins. As i it is going to be part of a code to be executed on Hadoop cluster and will contain ~100 million entries, i need smallest possible retrieval time. Also another helpful information: currently the data (keys) which is being inserted is range of integers from 1,2,...

C++ make_shared not available

柔情痞子 提交于 2019-11-30 05:42:37
问题 While I have std::tr1::shared_ptr<T> available in my compiler, I don't have make_shared . Can someone point me to a proper implementation of make_shared ? I see that I need to use varargs to provide arguments to constructor of T. But I don't have variadic templates available in my compiler as well. 回答1: If your compiler don't give an implementation of make_shared and you can't use boost, and you don't mind the lack of single-allocation optimization both for the object and the reference

enable_if method specialization

狂风中的少年 提交于 2019-11-30 03:54:09
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::enable_if<std::is_same<Q, T>::value && std::is_floating_point<Q>::value, A<T> >::type operator% ( const Q&

Typedef a template class without specifying the template parameters

我的未来我决定 提交于 2019-11-29 23:00:00
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 until official c++0x standard is available. So does anyone know an elegant workaround for this? #ifdef _TR1 #include <unordered_map> typedef std::tr1::unordered_map MyMap; //error C2976: too few template arguments #else #include <map> typedef std::map MyMap; //error C2976: too few template arguments #endif The way I've seen this done is to wrap the

Extracting a raw pointer from a shared_ptr

混江龙づ霸主 提交于 2019-11-29 17:56:23
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 object back to the user I want to give back the raw pointer. However, I have not found a way to do that.

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

拈花ヽ惹草 提交于 2019-11-29 13:40:11
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 another container. I could certainly write such a function object but I'd prefer to reuse something that's had a lot of eyeballs on it. boost::bind is what you look for. boost::bind(&std::pair::second, _1); // returns the value of a pair Example: typedef std::map

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

旧时模样 提交于 2019-11-29 11:27:27
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... Yakk - Adam Nevraumont 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 in the implementation and/or use of the feature, and if everything works they can

Differences between different flavours of shared_ptr

蹲街弑〆低调 提交于 2019-11-29 09:14:00
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? 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 and pointer arithmetic, but the C++0x version will add these. If your code works with the TR1/Boost version,

Using TR1 libraries in GCC and MSVC

ε祈祈猫儿з 提交于 2019-11-29 06:29:58
I would like to use the TR1 libraries that ship with modern versions of GCC and MSVC, but there are subtle differences: in GCC, I have to say #include <tr1/memory> std::tr1::shared_ptr<int> X; while in MSVC I have to say #include <memory> std::shared_ptr<int> X; I have two questions: 1) Does MSVC automatically operate in C++0x-mode (equivalent to GCC's std=c++0x), or does it also work in C++98/03 mode by default? 2) How can I unify the includes and namespaces? I was thinking about a preprocessor macro of the sort "INCLUDE_TR1(memory)" or something like that. To clarify, I want to use the