tr1

std::regex equivalent of '/g' global modifier

∥☆過路亽.° 提交于 2019-12-03 08:29:52
In Perl, I can do this: $text = '1747239'; @matches = ($text =~ m/(\d)/g); # @matches now contains ('1', '7', '4', '7', '2', '3', '9') Using C++ regex matching, what's the best way to replicate this behaviour so that I get a match set including all the matches? I have this at the moment:- compiledRegex = std::regex(regex, std::tr1::regex_constants::extended); regex_search(text, results, compiledRegex); int count = results.size(); // Alloc pointer array based on count * sizeof(mystruct). for ( std::cmatch::iterator match = results.begin(); match != results.end(); ++match ) { // Do something

Is it legal to place using tr1::shared_ptr in namespace std in header?

牧云@^-^@ 提交于 2019-12-03 08:06:43
Is it legal and good programming style to use std::tr1::shared_ptr as std::shared_ptr placing using directive in corresponding header ? Like this: namespace std { using tr1::shared_ptr; } I know that it's bad to pollute entire namespace but what about this case? Are there any hidden gotchas? Target compiler is VS2008 but compatibility with later versions is also desired. Technically, the Standard says that you enter the realm of Undefined Behavior if you do this: 17.6.4.2.1 Namespace std [namespace.std] 1 The behavior of a C++ program is undefined if it adds declarations or definitions to

Defining a hash function in TR1 unordered_map inside a struct

£可爱£侵袭症+ 提交于 2019-12-03 03:48:55
According to this , it is possible to define an equality function in a TR1 unordered_map like this: #include <tr1/unordered_map> using namespace std; using namespace std::tr1; struct foo{ ... bool operator==(const foo& b) const{ return ..; } }; unordered_map<foo,int> map; Is it possible to define the hash function the same way? If you want to change the default hashing (or, more often, provide hashing for a type that isn't currently supported), you provide a specialization of std::tr1::hash<T> for your key-type: namespace std { namespace tr1 { template<> struct hash<typename my_key_type> { std

How does one include TR1?

隐身守侯 提交于 2019-12-02 23:36:42
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 get G++ to accept the second version? How does one in general handle TR1 in a portable way? Install boost on your machine. Add the following directory to your search path. <Boost Install Directory>/boost/tr1/tr1 see here boost tr1 for details Now when you include

Idiomatic use of std::auto_ptr or only use shared_ptr?

╄→尐↘猪︶ㄣ 提交于 2019-12-02 20:36:42
Now that shared_ptr is in tr1, what do you think should happen to the use of std::auto_ptr ? They both have different use cases, but all use cases of auto_ptr can be solved with shared_ptr , too. Will you abandon auto_ptr or continue to use it in cases where you want to express explicitly that only one class has ownership at any given point? My take is that using auto_ptr can add clarity to code, precisely by adding nuance and an indication of the design of the code, but on the other hand, it add yet another subtle issue when training new programmers: they need to understand smart pointers and

returning a 'pointer' which is required to be held by a smart pointer

六月ゝ 毕业季﹏ 提交于 2019-12-02 19:40:21
I have a project which I would like to make more use of smart pointers. Overall, I have been successful in this goal. However, I've come across one things which I'm not sure what the "best practice" is. Basically I would like to return a "pointer" from a function, but require that the user hold it in a smart pointer. Not only that, I don't want to mandate a particular smart pointer (shared vs. scoped). The problem is mostly that there doesn't seem be to a proper way to upgrade a scoped_ptr to a shared_ptr (that would be the ideal solution i think). I understand why they didn't do this, as it

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

六眼飞鱼酱① 提交于 2019-12-01 23:34:16
问题 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: inline void operator += (action func) { callbacks.push_back(func); } inline void operator -= (action func) { callbacks.remove(func); } void operator ()(T1 arg1) { for

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-01 16:48:03
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 boost::tr1::shared_ptr. Now that the code is being used more widely outside of our research group,

Does std::function's copy-constructor require the template type's argument types to be complete types?

浪尽此生 提交于 2019-11-30 15:32:05
问题 Given: #include <functional> class world_building_gun; class tile_bounding_box; typedef std::function<void (world_building_gun, tile_bounding_box)> worldgen_function_t; void foo() { worldgen_function_t v; worldgen_function_t w(v); } Should this compile? My compilers say: Yes: GCC/stdlibc++ (also boost::function is yes in both GCC and Clang) No: Clang/libc++ ( http://libcxx.llvm.org/ , Clang 3.0, libc++ SVN as of today) (If "no" is the correct answer, I will fix my real code to put complete

Does std::function's copy-constructor require the template type's argument types to be complete types?

与世无争的帅哥 提交于 2019-11-30 14:51:16
Given: #include <functional> class world_building_gun; class tile_bounding_box; typedef std::function<void (world_building_gun, tile_bounding_box)> worldgen_function_t; void foo() { worldgen_function_t v; worldgen_function_t w(v); } Should this compile? My compilers say: Yes: GCC/stdlibc++ (also boost::function is yes in both GCC and Clang) No: Clang/libc++ ( http://libcxx.llvm.org/ , Clang 3.0, libc++ SVN as of today) (If "no" is the correct answer, I will fix my real code to put complete types in more headers or use boost::function.) EDIT: Here is the Clang error message: In file included