std

Is there a range class in C++11 for use with range based for loops?

人走茶凉 提交于 2019-12-17 04:14:50
问题 I found myself writing this just a bit ago: template <long int T_begin, long int T_end> class range_class { public: class iterator { friend class range_class; public: long int operator *() const { return i_; } const iterator &operator ++() { ++i_; return *this; } iterator operator ++(int) { iterator copy(*this); ++i_; return copy; } bool operator ==(const iterator &other) const { return i_ == other.i_; } bool operator !=(const iterator &other) const { return i_ != other.i_; } protected:

Python generator that groups another iterable into groups of N [duplicate]

和自甴很熟 提交于 2019-12-17 03:42:47
问题 This question already has answers here : What is the most “pythonic” way to iterate over a list in chunks? (35 answers) Closed 3 years ago . I'm looking for a function that takes an iterable i and a size n and yields tuples of length n that are sequential values from i : x = [1,2,3,4,5,6,7,8,9,0] [z for z in TheFunc(x,3)] gives [(1,2,3),(4,5,6),(7,8,9),(0)] Does such a function exist in the standard library? If it exists as part of the standard library, I can't seem to find it and I've run

Is std::vector or boost::vector thread safe?

若如初见. 提交于 2019-12-17 02:23:22
问题 I have multiple threads simultaneously calling push_back() on a shared object of std::vector . Is std::vector thread safe? Or do I need to implement the mechanism myself to make it thread safe? I want to avoid doing extra "locking and freeing" work because I'm a library user rather than a library designer. I hope to look for existing thread-safe solutions for vector. How about boost::vector , which was newly introduced from boost 1.48.0 onward. Is it thread safe? 回答1: The C++ standard makes

How is std::string implemented?

亡梦爱人 提交于 2019-12-17 02:11:32
问题 I am curious to know how std::string is implemented and how does it differ from c string?If the standard does not specify any implementation then any implementation with explanation would be great with how it satisfies the string requirement given by standard? 回答1: Virtually every compiler I've used provides source code for the runtime - so whether you're using GCC or MSVC or whatever, you have the capability to look at the implementation. However, a large part or all of std::string will be

C++ OpenMP Parallel For Loop - Alternatives to std::vector [closed]

感情迁移 提交于 2019-12-17 00:12:11
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . Based on this thread, OpenMP and STL vector, which data structures are good alternatives for a shared std::vector in a parallel for loop? The main aspect is speed, and the vector might require resizing during the loop. 回答1: The question you link was talking about the fact that "that STL vector container is not

Why does stdlib.h's abs() family of functions return a signed value?

冷暖自知 提交于 2019-12-14 03:40:33
问题 The negative implication of this is noted in the man page: NOTES Trying to take the absolute value of the most negative integer is not defined. What's the reasoning behind this and what's the best recourse for a person who would like to avoid undefined behavior? Do I have to resort to something like: unsigned uabs(signed val) { return val > 0 ? val : (val == 1U << ((sizeof(val) * 8) - 1)) ? -1U : -val; } (Intentionally hacky to emphasize displeasure with stdlib ;-) Example Say you had a 4-bit

Regex error using MSVC 2013

◇◆丶佛笑我妖孽 提交于 2019-12-14 00:40:28
问题 I have a piece of xml like code to parse, using std::regex in MSVC 2013 <GLVertex> #version 450 core layout(location = 0) in vec3 pos; in VertexInfo{ vec2 uv; }vertexInfo; void main(){ gl_Position = vec4(pos, 1.0); vertexInfo.uv = pos.xy; } <GLVertex/> <GLFragment> #version 450 core layout(location = 0) uniform sampler2D g_map; uniform Color { vec4 color; }; layout(location = 0) out vec4 fragColor; void main(){ fragColor = texture(g_map, vertexInfo.uv); } <GLFragment/> Here is the pattern:

is it possible to set the default value of std::tr1::tuple?

谁说我不能喝 提交于 2019-12-13 19:26:29
问题 (i'm using Visual C+++ 2010) suppose i have defined a tuple like this: typedef std::tr1::tuple< int //i want to set its default value to 9 , double //i want to set its default value to 3.3 , int //i want to set its default value to 2 , double //i want to set its default value to -7.2 > Mytuple; i can do that in a struct. but i wonder if it is possible to do that in std::tr1::tuple . Besides, i want to know when shoud i use std::tr1:tuple or struct? anyone can help me? 回答1: A tuple is not a

Bad access to memory using strcat

♀尐吖头ヾ 提交于 2019-12-13 17:05:42
问题 I'm using linux. I have a function called like: PlayBackgroundIntroMusic((char *)"IntroMusic"); The functions is: void SoundManager:: PlayBackgroundIntroMusic( char * musicFile) { // Concatenate extension for each platform strcat (musicFile,audioExtension); CCLOG("musicFile: %c" musicFile); SimpleAudioEngine::sharedEngine()->playBackgroundMusic(std::string(CCFileUtils::fullPathFromRelativePath(musicFile)).c_str(), false); } But i having a bad access to memory on line: strcat (musicFile

C++ accessing vector

大城市里の小女人 提交于 2019-12-13 15:47:28
问题 I have std::vector which contains my own class and I have to access its functions and voids. class A { private: int var; vector<string> vec; public: void setVar(int i) { var = i; } void setVec(vector<string> a) { vec = a; } }; I have also return functions but I didn't bother to type them. And I have included all necessary files. int main() { vector<A> vec; for (int i = 0; i < 10; i++) { A tmp; tmp.setVar(i); vec.push_back(tmp); } for (int i = 0; i < 10; i++) { vector<string> tmp; tmp.push