std

What exactly is the returned data type for a particular std::bind?

 ̄綄美尐妖づ 提交于 2019-12-24 01:26:13
问题 First I have to say I have to know the returned data type from std::bind. I have a struct which is defined as typedef struct { UINT ID; CString NAME; boost::any Func;// 'auto' doesn't work here } CALLBACK; CALLBACK CallBackItems[]; Func is a function holder, I want it to hold different kinds of callback function. Somewhere I initialize CallBackItems like this: CallBackItems[] = { { 1, L"OnReady", std::bind(&CPopunderDlg::OnReady, pDlg) }, { 2, L"CustomFunction",std::bind(&CPopunderDlg:

Is thare in STL or BOOST map like container with find and pop operation?

和自甴很熟 提交于 2019-12-23 22:46:54
问题 I want my map to be searchable and I want to be capable to kick out from it elements that were inserted into it longest time ago (with api like map.remove(map.get_iterator_to_oldest_inserted_element()) ) like mix of queqe and map.. Is there any such container in STL or Boost? 回答1: You can use boost::multi_index using the ordered_unique and sequence indices, as in this example. #include <iostream> #include <boost/multi_index_container.hpp> #include <boost/multi_index/ordered_index.hpp>

Visual Studio std::stringstream pubsetbuf does not work

≯℡__Kan透↙ 提交于 2019-12-23 20:06:17
问题 pubsetbuf member of std::stringbuf is not working at all in Visual Studio 2010! The code: char *FileData = ... ; unsigned long long FileDataLen = ... ; std::stringstream *SS = new std::stringstream(std::stringstream::in | std::stringstream::out); SS->rdbuf()->pubsetbuf( FileData, (std::streamsize)FileDataLen ); pubsetbuf does nothing in Visual Studio!!! Workaround #1 : std::stringstream *SS = new std::stringstream( std::string(FileData, (size_type)FileDataLen ) ),std::stringstream::in | std:

sorting std vector of strings without using default algorithm

∥☆過路亽.° 提交于 2019-12-23 19:41:21
问题 I have an std::vector of std::strings , each of which is a filename. Suppose filenames are of the format some_name_n.xyz . The problem is that some_name_10.xyz is less than some_name_2.xyz . The files are produced by some other process. What is the least painful way to sort them so that the number after '_' is considered for comparison, and not just its length? 回答1: std::sort allows you to specify a binary function for comparing two elements: http://www.cplusplus.com/reference/algorithm/sort/

std::get_time on Visual 2015 does not fail on incorrect date

我们两清 提交于 2019-12-23 18:28:13
问题 I'm executing the following code on Windows with Visual Studio 2015. Basically I use std::get_time to parse a date, but when the date is invalid, for example, a day greater than 31, it does not seem to set the fail bit on the stream. I have tried this on Ubuntu with g++ 5.4.0 and it sets the fail bit and prints "Parsing failed!". Is this a bug on Windows or am I doing something wrong. Thanks in advance! std::string date = "2019-2-37 23:00:00"; // day (37) is wrong. std::string format = "%Y-%m

Counting matches in vector of structs.

拟墨画扇 提交于 2019-12-23 18:04:19
问题 I have a problem that requires me to count the number of instances within this array that uses either the std::count() or std::find(). I'm aware of how to do this using a standard data(see bottom code) type but not with the NameContainer that I'm using. //Type struct NameContainer{ char name [32]; } //An array of containers NameContainer *_storedNames = new NameContainer[_numberOfNames]; //An example of what I'm trying to do with a string rather than the NameContainer std::vector<string> v(

On namespace 'names': ::std:: vs std::

♀尐吖头ヾ 提交于 2019-12-23 17:10:30
问题 I have been looking over some posts here on Stackoverflow, and I have noticed that most people use std:: but some people uses ::std:: I think i have read something about a global scope or something like that in namespaces as a reason to use ::std:: (but i can't find it now, because it was in a comment to an unrelated question) Is there any reason to prefer one way versus the other? 回答1: It's a bad idea to write code like this, but you could : namespace foo { namespace std { int bar; } std:

clang doesn't know std::atomic_bool, but XCode does

心不动则不痛 提交于 2019-12-23 16:24:07
问题 I'm trying to compile C++11 code that declares a variable of type std::atomic_bool. This is on Mac OS 10.8.2 with clang: clang --version Apple clang version 4.1 (tags/Apple/clang-421.11.66) (based on LLVM 3.1svn) Target: x86_64-apple-darwin12.2.0 Thread model: posix clang complains about std::atomic_bool: clang++ -c -stdlib=libc++ -msse4 -std=c++11 -Wno-unused-parameter -I. -o query.o query.cpp In file included from query.cpp:1: [...] ./threadutils.h:33:10: error: no type named 'atomic_bool'

How to combine std::copy_if and std::transform?

一个人想着一个人 提交于 2019-12-23 10:54:54
问题 consider this code snippet : iteration over one container of a first type T1 for creating a second container of a second type T2 applying a transformation function T1->T2 but only for T1 elements verifying a predicate (T1 -> bool ) (is Odd in the following example). std::vector<int> myIntVector; myIntVector.push_back(10); myIntVector.push_back(15); myIntVector.push_back(30); myIntVector.push_back(13); std::vector<std::string> myStringVectorOfOdd; std::for_each(myIntVector.begin(), myIntVector

Friending classes defined in the std namespace: any guarantees?

放肆的年华 提交于 2019-12-23 10:04:39
问题 This question came up as I answered this question: does the standard allow and make any guarantees about friend -ing standard library classes and/or functions? In this particular case, the situation the question was whether: class MyUserDefinedType { friend struct std::default_delete<MyUserDefinedType>; private: ~MyUserDefinedType() { } } is guaranteed to allow MyUserDefinedType to be stored in a std::unique_ptr<MyUserDefinedType> or std::shared_ptr<MyUserDefinedType> object with the default