tr1

Link TR1 on Ubuntu?

依然范特西╮ 提交于 2020-01-05 00:41:43
问题 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_regex<_Ch_type, _Rx_traits>&, std::tr1::regex_constants::match_flag_type) [with _Bi_iter = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std:

Link TR1 on Ubuntu?

只谈情不闲聊 提交于 2020-01-05 00:40:08
问题 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_regex<_Ch_type, _Rx_traits>&, std::tr1::regex_constants::match_flag_type) [with _Bi_iter = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std:

How does one include TR1?

蹲街弑〆低调 提交于 2019-12-31 11:27:52
问题 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? 回答1: Install boost on your machine. Add the following directory to your

Difference in performance between map and unordered_map in c++

独自空忆成欢 提交于 2019-12-30 01:46:27
问题 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

How does weak_ptr work?

时间秒杀一切 提交于 2019-12-28 02:26:26
问题 I understand how to use weak_ptr and shared_ptr . I understand how shared_ptr works, by counting the number of references in its object. How does weak_ptr work? I tried reading through the boost source code, and I'm not familiar enough with boost to understand all the things it uses. Thanks. 回答1: shared_ptr uses an extra "counter" object (aka. "shared count" or "control block") to store the reference count. (BTW: that "counter" object also stores the deleter.) Every shared_ptr and weak_ptr

TR1 function multicast

╄→尐↘猪︶ㄣ 提交于 2019-12-25 05:19:11
问题 How would you implement multicast for TR1 functors? I have my callback slots implemented like void setCallback(std::tr1::function<void (std::string)> cb) { this->callback = cb; } but need to pass more than one callback in one of them. I don't want to go into more complex solutions like observer, as this is the only case I need multicast so far. I also cannot use Boost.Signals (as suggested here), because I cannot use Boost. I don't need to explicitly handle disabling callback when subscriber

Workaround to allow tr1::function to swallow return values

爷,独闯天下 提交于 2019-12-24 10:55:41
问题 As a follow-up to Can tr1::function swallow return values?, how can one work around the limitation that tr1::function cannot swallow return values? This should work in the specific case of swallowing the return value of a callable object taking no arguments: template<typename FuncT> struct swallow_return_t { explicit swallow_return_t(FuncT i_Func):m_Func(i_Func){} void operator()(){ m_Func(); } FuncT m_Func; }; template<typename FuncT> swallow_return_t<FuncT> swallow_return(FuncT f) { return

C++ how to handle tr1 and non-tr1 namespaces in portable code?

允我心安 提交于 2019-12-24 05:04:05
问题 Is there a canonical way to deal with the namespace issues that arise when trying to maintain portable code between a TR1 and non-TR1 toolchain? I have a VC++2010 project that #include <type_traits> . I also have an LLVM 3.0 compiler that can handle this fine. This allows me to use templates such as: std::enable_if<typename> std::is_enum<typename> However I also need to build and maintain this code on an Xcode 4.5 clang compiler: $ /Applications/Xcode.app/Contents/Developer/Toolchains

Boost Serialization - Serialize std::tr1::shared_ptr?

核能气质少年 提交于 2019-12-24 03:06:04
问题 Boost::Serialization has builtin support for boost::shared_ptr<> . Is there a way to use this support for std::tr1::shared_ptr<> too? Is it possible to cast from std::tr1::shared_ptr<> to boost::shared_ptr<> ? 回答1: A casting will not be possible as implementations differ. Also creating an instance of the one shared_ptr type with the value returned from get() on the other shared_ptr type will not work correctly as the reference countings will go to 0 at different points in your code which

out of range random number generation in C++ using tr1

假装没事ソ 提交于 2019-12-24 02:27:33
问题 I am trying to generate number from a uniform distribution of real number in the range of [0, 1). But compiler is generating numbers which are out of [0, 1) range. Here is the code: int main(void) { // Solver solve; mt19937 mteng; mteng.seed(rdtsc()); uniform_real<double> uniRealD; double randomNum; for (int index = 0; index < 10; index++){ randomNum = uniRealD(mteng); if(randomNum<0.5) cout<<index<<" no. random number is: "<<randomNum<<endl; else cout<<"number generate is not in range"<<endl