standard-library

When is #include <new> library required in C++?

ぃ、小莉子 提交于 2019-11-27 19:16:17
According to this reference entry for operator new ( http://www.cplusplus.com/reference/std/new/operator%20new/ ) : Global dynamic storage operator functions are special in the standard library: All three versions of operator new are declared in the global namespace, not in the std namespace. The first and second versions are implicitly declared in every translation unit of a C++ program: The header does not need to be included for them to be present. This seems to me to imply that the third version of operator new (placement new) is not implicitly declared in every translation unit of a C++

What are the rules for function pointers and member function pointers to Standard functions?

狂风中的少年 提交于 2019-11-27 18:38:34
问题 What are the existing rules for taking function pointers or member function pointers to Standard functions? For example, something like auto p = &std::string::size; Is this legal? Would it be more or less legal if I explicitly requested the correct type, so it would function even if there was an additional implementation-added overload of std::string::size ? 回答1: Using the "correct" type doesn't make things better: Except for the virtual functions all functions in the standard C++ library can

Concatenating strings doesn't work as expected [closed]

时光毁灭记忆、已成空白 提交于 2019-11-27 11:10:17
I know it is a common issue, but looking for references and other material I don't find a clear answer to this question. Consider the following code: #include <string> // ... // in a method std::string a = "Hello "; std::string b = "World"; std::string c = a + b; The compiler tells me it cannot find an overloaded operator for char[dim] . Does it mean that in the string there is not a + operator? But in several examples there is a situation like this one. If this is not the correct way to concat more strings, what is the best way? Your code, as written, works. You’re probably trying to achieve

How can I tell if a Perl module is core or part of the standard install?

微笑、不失礼 提交于 2019-11-27 10:40:17
问题 How can I check if a Perl module is part of the core - i.e. it is part of the standard installation? I'm looking for: a command-line command: a Perl subroutine/function to check within code Perhaps the question should be: How can I tell what modules were originally provided with the specific Perl installation on a machine? (Actually, it is now asked as How can I tell what modules were originally provided with the specific Perl installation on a machine? .) Given that there now appears to not

How to check if a file exists in Go?

妖精的绣舞 提交于 2019-11-27 09:57:45
Go's standard library does not have a function solely intended to check if a file exists or not (like Python's os.path.exists ). What is the idiomatic way to do it? Sridhar Ratnakumar To check if a file doesn't exist, equivalent to Python's if not os.path.exists(filename) : if _, err := os.Stat("/path/to/whatever"); os.IsNotExist(err) { // path/to/whatever does not exist } To check if a file exists, equivalent to Python's if os.path.exists(filename) : Edited: per recent comments if _, err := os.Stat("/path/to/whatever"); err == nil { // path/to/whatever exists } else if os.IsNotExist(err) { //

Why is Haskell missing “obvious” Typeclasses

荒凉一梦 提交于 2019-11-27 09:50:54
问题 Consider the Object-Oriented Languages: Most people coming from an object-oriented programming background, are familiar with the common and intuitive interfaces in various languages that capture the essence of Java's Collection & List interfaces. Collection refers to a collection of objects which doesn't necessarily have an natural ordering/indexing. A List is a collection which has a natural ordering/indexing. These interfaces abstract many library data-structures in Java, as do their

Should I call reset() on my C++ std random distribution to clear hidden state?

馋奶兔 提交于 2019-11-27 07:40:40
问题 I would like to wrap the random number distributions from the C++11 standard library with simple functions that take as arguments the distribution's parameters and a generator instance. For example: double normal(double mean, double sd, std::mt19937_64& generator) { static std::normal_distribution<double> dist; return dist(generator, std::normal_distribution<double>::param_type(mean, sd)); } I want to avoid any hidden state within the distribution object so that each call to this wrapper

“Unresolved inclusion” error with Eclipse CDT for C standard library headers

六月ゝ 毕业季﹏ 提交于 2019-11-27 06:31:13
I set up CDT for eclipse and wrote a simple hello world C program: #include <stdio.h> int main(void){ puts("Hello, world."); return 0; } The program builds and runs correctly, but eclipse keeps showing this yellow question mark by the side of inclusion statement that says "Unresolved inclusion: <stdio.h>" when I put mouse over it. It doesn't affect running of the program but I find it rather annoying. Does anyone have any idea how to remove it ? The compiler Eclipse is using is able to resolve the symbols just fine, so the code will compile fine. But the code-completion/preprocessor Eclipse is

What is std::decay and when it should be used?

≯℡__Kan透↙ 提交于 2019-11-27 05:53:26
What are the reasons for the existence of std::decay ? In what situations is std::decay useful? <joke>It's obviously used to decay radioactive std::atomic types into non-radioactive ones.</joke> N2609 is the paper that proposed std::decay . The paper explains: Simply put, decay<T>::type is the identity type-transformation except if T is an array type or a reference to a function type. In those cases the decay<T>::type yields a pointer or a pointer to a function, respectively. The motivating example is C++03 std::make_pair : template <class T1, class T2> inline pair<T1,T2> make_pair(T1 x, T2 y)

How to handle key press events in c++

本秂侑毒 提交于 2019-11-27 05:12:48
I am writing a custom console program. And I want to make it look like an actual one. So I want to bind some actions with keypress events. For example when the up arrow is pressed previously executed commands should be shown to the user. I know about SDL. But I think that it's not a standard library, is it ?? If there is other alternative of it, that included in standard CPP library, please let me know. Thanks. You won't find anything in the standard library for that. It's all Platform-dependent. In Windows, you have functions like GetAsyncKeyState to get the state of a key on the keyboard for