tr1

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 of all its calls. The scenario would look like this: // a function whose runtime shoul...

[c++] 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 provide the function for intersection, union, difference.. Since that's the basic operation o...

Differences between different flavours of shared_ptr

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? ...

C++ TR1: how to use the normal_distribution ?

Hi, I'm trying to use the C++ STD TechnicalReport1 extensions to generate numbers following a normal distributions, 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;...

Determine compile-time existence of include files in C++

I'm trying to write some portable C++ library code that will initially rely on Boost.Regex, and then move to TR1 as compilers support it, and eventually to the C++0x specification after things get moved from the std::tr1 namespace to std. Here is some pseudo-code for what I'd like to do with the preprocessor: if( exists(regex) ) // c...

How does one include TR1?

Different compilers seem to have different ideas about TR1. G++ only seems to accept includes of the type: #include <tr1/unordered_map> #include <tr1/memory> ... While Microsofts compiler only accept: #include <unordered_map> #include <memory> ... As for as I understand TR1, the Microsoft way is the correct one. Is there a way to ...

How can I use std::remove on a container with std::tr1::weak_ptr?

If I had a STL container, say a list of pointers I could remove them like in the exmple below. With a container of weak_ptrs this does not work, because they cannot be compared, as they need to be locked first. What can I do? void MyClass::RemoveItem(std::tr1::weak_ptr<Item> const & pItem) { mylist.remove(pItem); } ...

Accessing a nested pair

To take apart a pair, the following can be done boost::bind(&std::pair::second, _1); // returns the value of a pair What about using combinations of different containers, how can a nested pair be accessed? For example when I wanted to partition a vector into items contained in a supplemental map and items that where not contained in ...

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 until official c++0x standard is available. So does anyone know an elegant workaround for t...

Reversing strings in a vector using for_each and bind

Hi! I was wandering how it's possible to reverese strings that are contained in a vector using a single for_each command just in one "simple" line. Yea, I know it is easy with a custom functor, but I can't accept, that it can't be done using bind (at least I couldn't do it). #include <vector> #include <string> #include <algorithm> std...

How does compiler choose between template specializations featuring an array?

I just came across std::tr1::extent template and it puzzled me. I never ever dealt with array type parameters in my life so I don't understand how they work. So, given the code from gcc type_traits template<typename _Tp, unsigned _Uint, std::size_t _Size> struct extent<_Tp[_Size], _Uint> template<typename _Tp, unsigned _Uint> ...

Best way to store and hash <int, int> key (C++)

My goal is to create an efficient structure to store the most relevant entries of a matrix that would (in a world without memory limitations) be approximately 10^5 x 10^5 and filled with doubles. The matrix is symmetric, so it actually would contain only (10^10)/2 values. I need to access entries many, many times in my simulation, so fa...

Regex pattern help wanted

The raw string is like this: {\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\froman\fcharset0 Times New Roman;}{\f1\fnil\fcharset0 MS Shell Dlg 2;}} \viewkind4\uc1\pard\sb100\sa100\f0\fs24\u30340?\u27494?\u35013?\u20998?\u23376?\u65292?23\u26085?\u22312?\u33778?\u24459?\u23486?\u21335?\u37096?\u30340?\u39532?\u20140?\par \pard\f1...

What will happen to namespace tr1 when c++ xx is approved?

I'm writing some stuff using the tr1 namespace in VS2008. What will happen when C++xx becomes ratified? Has this happened before with other C++ revisions? Will the tr1 stuff still work or will I have to change all of my include? I realize that I'm making the very large assumption that this ratification will someday occur. I know that mos...

Is there any way to have dot (.) match newline in C++ TR1 Regular Expressions?

I couldn't find anything regarding this on http://msdn.microsoft.com/en-us/library/bb982727.aspx. Maybe I could use '[^]+' to match everything but that seems like a hack? Thanks. ...

Creating multicast events with std::tr1::function (or boost::function)

I'm attempting to create C#-like multicast delegates and events using features from TR1. Or Boost, since boost::function is (mostly) the same as std::tr1::function. As a proof of concept I tried this: template<typename T1> class Event { private: typedef std::tr1::function<void (T1)> action; std::list<action> callbacks; public: inli...

tr1::function WINAPI

How can I use tr1::function with WINAPI calling convention ? (at least in windows). I can use visual c++ 9 SP1 TR1 or BOOST's one... typedef void (WINAPI *GetNativeSystemInfoPtr)(LPSYSTEM_INFO); HMODULE h = LoadLibrary (_T("Kernel32.dll")); GetNativeSystemInfoPtr fp = (GetNativeSystemInfoPtr) GetProcAddress (h,"GetNativeSystemInfo"); SY...

Difference in performance between map and unordered_map in c++

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...

The difference between python dict and tr1::unordered_map in C++

I have a question related to understanding of how python dictionaries work. I remember reading somewhere strings in python are immutable to allow hashing, and it is the same reason why one cannot directly use lists as keys, i.e. the lists are mutable (by supporting .append) and hence they cannot be used as dictionary keys. I wanted to...

Link TR1 on Ubuntu?

I have written a class using std::tr1::regex, and I don't know how to link it. I get (sorry for the large dump...) : $ g++ DictReader.cpp -std=c++0x /usr/include/c++/4.4/tr1_impl/regex:2255: warning: inline function ‘bool std::tr1::regex_search(_Bi_iter, _Bi_iter, std::tr1::match_results<_Bi_iter, _Allocator>&, const std::tr1::basic_re...