tr1

How to handle evolving c++ std:: namespace? e.g.: std::tr1::shared_ptr vs. std::shared_ptr vs. boost::shared_ptr vs. boost::tr1::shared_ptr

偶尔善良 提交于 2019-12-19 17:28:33
问题 For the code I am currently working on, we sometimes need to compile on some older systems with older compilers (e.g.- we run sims on an older IBM BlueGene/L, who's support contract dictates some quite old C++ compiler). The code itself makes use of shared_ptrs, and was originally written to use std::tr1::shared_ptr. When compiling on the old BlueGene machine, I quickly realized that it doesn't have a tr1:: implementation, and so I switched to boost::shared_ptr. Turns out there is also a

How to make tr1::array allocate aligned memory?

元气小坏坏 提交于 2019-12-19 03:40:57
问题 You can allocate a std::vector which allocates aligned heap memory by defining your own allocator. You can allocate a c-style array on the stack using declspec align. But can you declare a tr1::array which guarantees that the element at index zero will be aligned? 回答1: tr1::array (and std::array and boost::array ) are POD, so the memory occupied by the contents is coincident with the memory of the array . So, allocate the array however you need to, and construct it with placement new .

Typedef a template class without specifying the template parameters

倾然丶 夕夏残阳落幕 提交于 2019-12-18 10:33:49
问题 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:

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

谁都会走 提交于 2019-12-18 07:47:06
问题 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. 回答1: boost::bind is what

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

坚强是说给别人听的谎言 提交于 2019-12-18 07:47:03
问题 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. 回答1: boost::bind is what

Using TR1 libraries in GCC and MSVC

一世执手 提交于 2019-12-18 04:43:20
问题 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

Comparing std::tr1::function<> objects

好久不见. 提交于 2019-12-17 17:22:06
问题 I've been trying to implement a C#-like event system in C++ with the tr1 function templates used to store a function that handles the event. I created a vector so that multiple listeners can be attached to this event, i.e.: vector< function<void (int)> > listenerList; I'd like to be able to remove a handler from the list to stop a listener receiving events. So, how can I find the entry in this list that corresponds to a given listener? Can I test if a 'function' object in the list refers to a

How can I force MinGW to use tr1 namespace?

不想你离开。 提交于 2019-12-13 14:30:44
问题 I'm using MinGW 4.5.2 and I'd like to use unordered_map from the tr1 namespace, not the one from std namespace that is enabled by passing -std=c++0x. I'm sure this can be done since there are two unordered_map files, and one is in the tr1 sub-directory. Clarification: I'm also compiling this code with msvc10 and it supports unordered_map in both namespaces but only in one location. So I'd like to make it compile with both compilers with changing as least as possible. 回答1: Include <tr1

How to convert string to regex literal

陌路散爱 提交于 2019-12-12 16:25:46
问题 What's the best way to escape an arbitrary std::wstring for use inside a regular expression? For example, convert you owe me $ to you owe me \$ ? My scenario: I want to use a std::tr1::wregex to search for a whole word. So I want to do something like: std::wstring RegexEscape(const std::wstring& inp) { return ????? } bool ContainsWholeWord(const std::wstring& phrase, const std::wstring& word) { std::tr1::wregex regex(std::wstring(L"\\b") + RegexEscape(word) + L"\\b"); return std::tr1::regex

C++ TR1 regex - multiline option

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-12 10:48:19
问题 I thought that $ indicates the end of string. However, the following piece of code gives "testbbbccc" as a result, which is quite astonishing to me... This means that $ actually matches end of line, not end of the whole string. #include <iostream> #include <regex> using namespace std; int main() { tr1::regex r("aaa([^]*?)(ogr|$)"); string test("bbbaaatestbbbccc\nddd"); vector<int> captures; captures.push_back(1); const std::tr1::sregex_token_iterator end; for (std::tr1::sregex_token_iterator