Quantcast
Channel: My Filter (2) - Stack Exchange
Browsing latest articles
Browse All 218 View Live

How do I let the result of std::transform accumulate on an array instead of...

When I want to compute the pairwise product of two arrays, a and b and store the result in another array, c, I may use std::transform.long int length = 10000;double* a = new double[length];double* ...

View Article


C++ custom allocators: in what circumstances would I be asked to return more...

I've written several memory allocator that couldn't allow the allocation of more than 1 unit of the specified type T, as apparently required by the Standard C++ library's collections that take ...

View Article


How to implement a generic publish–subscribe pattern where methods of...

More generic publish–subscribe patternI was looking for a publish–subscribe pattern that is advance in terms of more generic.The usual publish–subscribe pattern that I know of has virtual functions ...

View Article

is there an overhead when using operator compared to operator< etc –...

will there be a difference in performance between these examples and use < or == operators?struct Data { int x; int y; bool operator<(const Data& other) const { if (x ...

View Article

What are the arguments of comp for lower_bound() in C++? – stackoverflow.com

I'm trying to create a custom comparison function for the binary search method lower_bound(). I've tried reading the docs and searching, but I can't figure out how the arguments of the comp function ...

View Article


How do I initialize an inplace key value pair in std::map – stackoverflow.com

I want to insert key value pairs into a std::map with uint32_t as the key type and a custom type for values. Based on the documentation of std::map, I wrote the following code:#include ...

View Article

C++/STL: get warnings about empty iterator ranges – stackoverflow.com

I had a bug that boiled down tovector<T> to_be_sorted;std::sort(to_be_sorted.begin(), to_be_sorted.begin(), [](const auto &lhs, const auto &rhs) { /* sort code* /});(yes, I passed ...

View Article

How to replace some columns of a matrix using std::valarray and std::gslice –...

I have a set of consecutive numbers from 1 to 24. I interpret this set as a 4 by 6 matrix using std::valarray:std::valarray va{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ...

View Article


Can liveliness analysis cause a c++ object to be destructed before leaving...

I was thinking of a situation e.g. like this:void example() { vector<unique_ptr<int>> v; v.emplace_back(make_unique<int>(1)); int *a = v.back().get(); { // rest of code, ...

View Article


Will adding std::string items to std::deque with std::move be more efficient?...

In this code:// build string requiring a bunch of processingstd::wstring xmlstr=xml->GetXml();{ std::lock_guard<std::mutex> guard(my_mutex); m_deque.push_back(std::move(xmlstr)); // ...

View Article

C++ How to convert a for loop to std::count_if – stackoverflow.com

Here's a code that, for each element, counts the number of elements that are not connected to it.bool conn[100][100];for(int i=0; i<N; i++){ int cnt=0; for(int j=0; j<N; j++) ...

View Article

Cannot convert to class – stackoverflow.com

I'm writing my custom initializer_list and pair. However, I met the converting fail problem: error: could not convert ‘{test::pair<std::__cxx11::basic_string<char>, std::__cxx11::...

View Article

Implementation of std::list::insert: casting away constness? – stackoverflow.com

Lately I was implementing my own linked list class and emulating the behavior of std::list for practicing purpose. I came across a problem about constness when implementing the insert method. I've ...

View Article


Circular dependency where two containers store iterators to each other's...

I wrote quick impl of LRU cache, where all the data (eg key -> value pairs) is stored in unordered map, and the order list simply stored pointers to these items.if it was regular C data structs, ...

View Article

Nested std::vector brings too many memory fragmentation and pollutes the...

In my projects, there are several std::vector<std::vector<int>> dynamic arrays. The first dimension is about 10 million, the second dimension is about 10-100. Both of the dimensions are ...

View Article


std::list with a custom allocator crashes when removing items –...

I wrote a memory allocator to use with standard containers. However, every time I try to remove an element from a std::list, the program crashes at the line l.remove(elt).I spent time investigating ...

View Article

Why does std::filesystem::absolute resolve . and .. on Windows but not on...

I'm using C++17's std::filesystem::absolute to convert relative paths to absolute ones. I noticed that on Windows (MSVC), this function seems to resolve . and .. components in the path, but on Linux ...

View Article


Clang&LLDB debug: summary string parsing error – stackoverflow.com

I have set the compilation option -fstandalone-debug, but still cannot view the string content in vscode with clangd & CodeLLDB.#include <iostream>#include <string>using namespace ...

View Article

What is the purpose of Microsoft-specific attributes msvc::known_semantics? –...

When I was using Visual Studio 2022, _MSVC_KNOWN_SEMANTICS is defined as [[msvc::known_semantics]] in the header file yvals_core.h.I try to find description in ...

View Article

How can I use a lightweight argument in unordered_set::find() method? –...

Must I fully build a Storage object for finding it, instead of using std::string because of having operator== for it?#include <cstddef>#include <functional>#include <string>#...

View Article

python gmsh: build 3D mesh from solid-split stl surface for openFOAM –...

I have a simple task- I have a closed stl-surface, the whole surface is split into solids. I need to use python gmsh pack to build 3D mesh (tetra or hexa) with named-selections (lets call it this way)...

View Article


Removing an element from a map of vectors – stackoverflow.com

std::map<unsigned long, std::vector<Foo*> > fKeys = myObject->GetFoo();for (auto it = fKeys.begin(); it != fKeys.end() && !found; ++it) for (auto it1 = 0; it1 < ...

View Article


Why std::vector::insert requires template to be CopyAssignable and...

N4868 22.2.3 table 77 Sequence container requirements states that insert(iterator pos, size_type count, T value) requires T to be CopyInsertable and CopyAssignable in any sequence container. It means...

View Article

Does std::find still guarantee first element with std::execution::par? –...

Parallel policy states that order of iterator evaluation is not guaranteed. However, std::find*, std::search and std::mismatch all say that they return first iterator matching condition. How do those...

View Article

What is the size of std::array? – stackoverflow.com

Unlike C array, std::array is allowed to have zero length. But the current implementations differ in how std::array<T,0> is implemented, in particular the sizes of the object are different.This...

View Article


How does Microsofts std::lib implementation perform debug iterator checks? –...

In the question Why does Microsoft's implementation of std::string require 40 bytes on the stack? the observation is made, that a std::string requires 8 additional bytes in Debug mode.After ...

View Article

Is there any way to iterate data members with STL algorithms using the C++26...

With C++26 reflection, we can simply iterate all data members of an object:#include <iostream>#include <meta>struct Foo { int x; int y;};void PrintFoo(const Foo& foo) { ...

View Article

What are your favorite C++ STL alternatives? – stackoverflow.com

I don't really like the C++ stl. It is too complex.I used to code in C and often had to use the OS APIs which are a lot of work and then decided to switch to C++ because it provides OS API ...

View Article

std::function discards lambda closure silently – stackoverflow.com

I have a class that does a conversion on a value using a lambda, which is captured in an std::function. This all works fine, until I try to capture a double while running on my embedded target (...

View Article



Static C++ check for pure virtual functions passed in constructor to...

C++ compilers warn if pure virtual functions are directly called in a constructor/destructor (but not indirectly).Binding a pure virtual function and storing the result in a class member and calling ...

View Article
Browsing latest articles
Browse All 218 View Live


Latest Images