c++-standard-library

different compare signature for std::upper_bound and std::lower_bound

自作多情 提交于 2019-12-06 01:51:41
问题 Here is a sample example for both std::lower_bound & std::upper_bound , notice the signature of Compare lambda being passed to them - const auto lower_x = std::lower_bound( points.begin(), points.end(), rec.min_corner.x, [](const RankedPoint &rp, const double x) { return rp.point.x < x; }); const auto upper_x = std::upper_bound( points.begin(), points.end(), rec.max_corner.x, [](const double x, const RankedPoint &rp) { return x < rp.point.x; }); What is the possible reasoning behind keeping

Why aren't std::count and std::find optimised to use memchr?

痞子三分冷 提交于 2019-12-06 01:05:59
问题 I was reading sehe's answer to this question and was surprised to see sehe found using a hand written loop using std::memchr to be over 3 times faster than using std::count (see comments). The code using std::count can be seen in edit 2, but it basically boils down to: const auto num_lines = std::count(f, l, '\n'); vs uintmax_t num_lines = 0; while (f && f != l) if ((f = static_cast<const char*>(memchr(f, '\n', l - f)))) num_lines++, f++; I would have expected the std::count version to be at

Why is there no language support in C++ for all C++ standard library type traits?

青春壹個敷衍的年華 提交于 2019-12-05 23:15:20
In C++ it is impossible to implement certain C++ standard library type traits without compiler intrinsics, using the C++ language only. Traits deal directly with C++ types. According to §17.6.1.3.2 freestanding implementations of the C++ standard library must implement <type_traits> . Doesn't this effectively mean that the C++ standard requires non-standard language extensions/compiler intrinsics from all compilers which support want to support freestanding C++ standard library implementations? Why were such type traits allowed into the standard without support in the core language? There are

Are C++11 containers supported by Cython?

亡梦爱人 提交于 2019-12-05 22:37:54
问题 Cython gives us an easy way to import C++ standard library data structures, e.g.: from libcpp.vector cimport vector from libcpp.utility cimport pair But what about newer containers introduced with C++11: std::unordered_map , std::unordered_set etc. Are they supported in the same way? I could not find the appropriate import statement. 回答1: Cython doesn't support them by default, but you could probably create your own interface, following the structure of https://github.com/cython/cython/blob

Clang 3.1 + libc++ Compile Error

情到浓时终转凉″ 提交于 2019-12-05 18:16:07
I've built and installed (under the prefix ~/alt ) LLVM-Clang trunk (23 apr 2012) successfully using GCC-4.6 on Ubuntu 12.04 and in turn libc++ using this Clang-build. When I want to use it I have to supply both -lc++ and -libstdc++ as follows /home/per/alt/bin/clang -x c++ -I/home/per/alt/include/v1 -L/home/per/alt/lib -std=gnu++0x -g -Wall ~/f.cpp -lm -lc++ -lstdc++ -lpthread -o f to compile f.cpp containing #include <iostream> using std::cout; using std::endl; int main(int argc, const char * argv[]) { cout << "sxx" << endl; return 0; } If I omit -lstdc++ I get the link error /home/per/alt

Is there a clean separating definition between “STL” and “C++ Standard Library”? [duplicate]

一个人想着一个人 提交于 2019-12-05 12:38:06
This question already has answers here : Closed 8 years ago . Possible Duplicate: What's this STL vs. “C++ Standard Library” fight all about? I am very much used to the term STL ("Standard Template Library") and I catch myself often using it when I really mean the C++ Standard Library . So, since almost everything in the C++(-11) Standard Library is a template nowadays, I wonder: Is there a definition what is STL and what is not, in the C++Standard-Lib? Maybe containers, streams, algorithms, etc? Or should I just stop using the term "STL", because it's the historic one that SGI (correct?) used

Why is {} used to access operator() in std::hash?

佐手、 提交于 2019-12-05 09:09:35
While reading the examples of std::hash used for std::unordered_map, I noticed that the operator() function was being accessed by {}. http://en.cppreference.com/w/cpp/utility/hash result_type operator()(argument_type const& s) const { result_type const h1 ( std::hash<std::string>{}(s.first_name) ); result_type const h2 ( std::hash<std::string>{}(s.last_name) ); return h1 ^ (h2 << 1); // or use boost::hash_combine (see Discussion) } What does the use of {} here represent? std::hash<T> is a type not a function. An instance of std::hash has an operator() that does the hash. So std::hash<std:

Initializing a std::vector with default constructor

爷,独闯天下 提交于 2019-12-05 08:57:39
I have a class field which is a std::vector. I know how many elements I want this vector to contain: N. How do I initialize the vector with N elements? std::vector has a constructor declared as: vector(size_type N, const T& x = T()); You can use it to construct the std::vector containing N copies of x . The default value for x is a value initialized T (if T is a class type with a default constructor then value initialization is default construction). It's straightforward to initialize a std::vector data member using this constructor: struct S { std::vector<int> x; S() : x(15) { } } class

How can unique_ptr have no overhead if it needs to store the deleter?

隐身守侯 提交于 2019-12-05 08:53:53
问题 First take a look at what C++ Primer said about unique_ptr and shared_ptr : $16.1.6. Efficiency and Flexibility We can be certain that shared_ptr does not hold the deleter as a direct member, because the type of the deleter isn’t known until run time. Because the type of the deleter is part of the type of a unique_ptr , the type of the deleter member is known at compile time. The deleter can be stored directly in each unique_ptr object. So it seems like that the shared_ptr does not have a

Error LNK2019: unresolved external symbol “toString(int)”

爱⌒轻易说出口 提交于 2019-12-05 08:40:44
Environment: Windows XP. Visual Studios 2010. Language - C++. I have run into the following link error & have run out of ideas how to fix this problem. I have a project (CnD Device) which links to 2 projects (Messages & Carbon) controlled by my group. I have tried to search for project properties between the 3 projects enter tcp_driver.obj : error LNK2019: unresolved external symbol "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl toString(int)" (?toString@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@H@Z) referenced in