Questions tagged [stl]
The Standard Template Library, or STL, is a C++ library of generic containers, iterators, algorithms, and function objects. When C++ was standardised, large parts of the STL were adopted into the Standard Library, and these parts in the Standard Library are also sometimes erroneously referred to collectively as "the STL".
14,490
questions
0
votes
0answers
9 views
How to save a 3D mesh as .stl file in WPF [closed]
In WPF I am trying to create a mesh of triangles and then save it as .stl file. currently i am able to create a mesh(collection of the triangles which are formed from 3d points)using Model3DGroup(),...
-1
votes
0answers
14 views
Looking for a STL File Parser [closed]
I am looking for a reader and writer STL file parser (binary and ASCII) for a project in Unity. I found some libraries but they doesn't explain how to use it or need any dependencies package. Any ...
2
votes
1answer
50 views
Big-O time complexity of 4sum problem. Brute force approach
I am doing this problem called 4sum. Link to problem.
Given an array of n numbers and an integer(this is the target
element). Calculate the total number of quads (collection of 4
distinct numbers ...
1
vote
1answer
51 views
Custom object's vector attribute median c++
I am trying to find the median value from the third attribute of my objects. My objects are in a vector.
std::vector<Object> obj =
{ Object {V , H , 5},
Object {C , B , 2},
Object {...
-1
votes
1answer
86 views
Does C++ have a data structure like a Python dictionary?
I am new to C++. I use a Python dictionary to store the data previously, now I am working on C++. Does C++ also have a data structure like Python's dictionary?
My scenario is as follows,
We have 4 ...
0
votes
3answers
79 views
RAM leaks on stl containers?
I have a RAM limit on my project, as it contains a lot of data manipulation . The problem is, I noticed that calling std::set<std::pair<int64_t, int64_t>>::clear() does not actually free ...
1
vote
1answer
38 views
Function taking either reference to single element or a vector
I want a function that modifies passed in elements of known type, matching against private data we iterate over in an outer loop comparing each to the passed in elements. Quantities are small so no ...
0
votes
0answers
18 views
Loading STL files with Vue-cli and Three.js
I currently have the problem that I am not able to load a STL file into a three.js scene which is created via vue-cli.
Project setup with vue-cli 'vue init webpack ProjectName', 'cd ProjectName', 'npm ...
1
vote
3answers
43 views
How to get the key of a map using the value in C++ STL
Get key by inputting the value of that key in C++ STL
map<int,int> m;
m[0]=8;
m[8]=7;
m[1562]=4;
m[100]=1;
auto i=m.find(1562);
cout<<endl<<i->first;
-2
votes
0answers
13 views
hi, I am wondering did anyone know how to do the conversion from java code to STL file?
3DObject obj = new 3DObject(20, 30, 10, true);
obj.exportToSTL("filename.stl");
I just making up some code as I not sure how to do the conversion.
3
votes
1answer
58 views
Why is inserting sorted keys into std::set so much faster than inserting shuffled keys?
I was accidentally surprised to found that inserting sorted keys into std::set is much much faster than inserting shuffled keys. This is somewhat counterintuitive since a red-black tree (I verified ...
0
votes
2answers
65 views
How to use a custom deleter using WinAPI with std::make_unique?
So I'm just experimenting with smart pointers and how I can manage Win32 HANDLE objects with them, so I wanted to test out this simple code I wrote.
It's supposed to provide a custom deleter for std::...
0
votes
1answer
49 views
Do we need to clear a class member of type vector in beginning of the constructor function of the class?
I am trying to understand the class definition of a class in this pdf: http://finance.bi.no/~bernt/gcc_prog/recipes/recipes.pdf (Page 61-62). The part of the code where I have the question is below. ...
0
votes
2answers
55 views
How to create an unordered_map with a range of numbers as keys | C++
int n;
unordered_map<int,int> map(1,n);
This gives me error. I want to initialize the map with keys ranging from 1 to n. How can I do that?
-1
votes
0answers
29 views
Something wrong my Regex or a bug in Apple's STL regex?
I have a regex I'm using to parse out a specific set of query parameters from a URL. However, I'm seeing it only capture whichever group appears last in the list. I'm aware this is normal behavior for ...
1
vote
1answer
31 views
Why am I getting an error with MSVC when using a C++17 parallel execution algorithm on Boost zip iterators?
I have some trouble using C++17 parallel execution algorithm with Boost iterators on MSVC. Here is my code:
#include <vector>
#include <execution>
#include <boost/range/combine.hpp>
...
-1
votes
0answers
27 views
How can I create std::weak_ptr<BaseClass> to an object? [duplicate]
I have a 3rd-party API which provides a method:
API::Register(std::weak_ptr<BaseClass> &o)
I have a class MyClass : public BaseClass and I want to do:
MyClass o;
API::Register(&o);
I ...
2
votes
5answers
86 views
How to compare two vectors for equality?
I have the following program:
std::vector<int> nums = {1, 2, 3, 4, 5};
std::vector<int> nums2 = {5, 4, 3, 2, 1};
bool equal = std::equal(nums.begin(), nums.end(), nums2.begin());
if (...
0
votes
1answer
34 views
Accumulate function in Vector (STL) giving negative sum
When i am coding the code below, i am getting a negative sum (-294967296).
#include<iostream>
#include<vector>
#include<numeric>
using namespace std;
int main() {
vector<long ...
0
votes
1answer
24 views
How can i convert stl into json from github python program
I am working on my college project: I need stl file converter into g-code using python program. For that, i have used this program file from github link - https://github.com/VanHulleOne/SciSlice (...
0
votes
1answer
46 views
Complexity of std::set constructor from sorted elements
Normally, constructing a rb-tree is O(N*log(N)) time.
However, initialization of std::set from sorted elements is linear time.
How does that work? Is there a sorted-check before initialization? Or ...
0
votes
1answer
31 views
Why STL list size() complexity is O(1) in C++11, how it is calculated?
Shouldn't it be O(n), because to calculate the size of a doubly linked list, we have to traverse it?
0
votes
0answers
24 views
Cleanest way to make a lambda that returns a const reference to a data member?
With the advent of std::views::transform and the addition of projections to std::algorithm, it becomes common to want a function that returns a const reference to a data member of its argument. For ...
0
votes
5answers
92 views
Creating containers c++ [closed]
I'm wondering if creating my own container is very useful ? There are a few containers already implemented in c++ but what are the advantages of creating my own container ?
More information : I am a ...
-1
votes
0answers
11 views
How to create STL file in python
I waould like to create STL file in python. I used numpy-stl but it creates open geometries that are not properly printable. Any suggestions?
2
votes
2answers
62 views
is it possible to using std::pair as key of std::set without any duplicates each element?
I'm trying to store struct in std::set using two integers in struct as key.
I know that is possible to using std::pair as key of std::set.
struct TYPE{
pair<int, int> nums;
... // some other ...
0
votes
1answer
58 views
Is there any method can print all member variable of a struct?
i have a series of struct, i want to add a show method for them.
please see the following code:
A {
int a, b, c;
void Show() {
cout << a << " " << b << " ...
0
votes
2answers
41 views
please help me with max_element function in c++ stl
Below is my code, I am new to C++ please help why this is giving error, I want to find max among element without using any extra space.
Code:
#include <bits/stdc++.h>
using namespace std;
...
-1
votes
1answer
34 views
How to change the object in a vector when I only have a reference to the vector in c++
I have to calculate the average of the peoples age and than I have to count how many people are younger than average. After that I have to age them up and count how many people are younger than the ...
0
votes
2answers
53 views
How to use multi-inheritence with std::shared_ptr?
So, I have code like this:
class IUpdatable {
virtual void onUpdate() = 0;
};
class IDrawable {
virtual void onDraw() = 0;
};
class IEventable {
virtual void onEvent() = 0;
};
class ...
0
votes
2answers
50 views
How to make template function work for char[32] and string type?
i want to design a template function, which build a shared memory with size = sizeof(T) * n
it returns template type pointer. and i pass a default value as default value.
function def looks like:
#...
0
votes
1answer
44 views
Min Heap Custom Comparator in C++
I have a Point Class and am creating a min-heap of Point objects.
class Point
{
int x;
int y;
public:
Point(int _x, int _y)
{
x = _x;
y = _y;
}
int getX() const { return ...
0
votes
2answers
86 views
Default value for the second element of the map STL?
what is the default value for second element in map STL if i am initializing it with an array?
for example:
#include <bits/stdc++.h>
using namespace std;
void countFreq(int arr[], int n)
{...
0
votes
1answer
30 views
adding node to bst results in the value being undefined
I am currently trying to re-implement map and I have the code below. When I create an object of class rb_tree and insert data using the insert function from that class everything works as expected, ...
2
votes
1answer
33 views
Explain behavior of default priority_queue::top()?
The std::priority_queue, by default uses a std::vector<int> and the std::less comparator. By default, priority_queue is a max heap.
The docs for top() states:
The top element is the element ...
0
votes
2answers
47 views
What are the implications of calling vector::size / map::size in a non-thread-safe manner?
As far as I can tell, map::size and vector::size, while const are not guaranteed thread-safe. One implementation of vector I found looks like this:
size_type size() const _NOEXCEPT
{return ...
0
votes
1answer
29 views
Difference between deque circular array and list implementation
From the research that I have done, it seems that deque is implemented either as a linked list or as a circular array. What is the difference in terms of performance between the two and why would one ...
0
votes
0answers
42 views
C++ How to use regular expressions and iterate over string with non-latin text?
I am working on an application that encodes information with different ciphers, for example, Atbash, Scytale, Caesar, etc. I decided to divide it into two parts: GUI with Qt and a separate library ...
-3
votes
2answers
80 views
What if sizeof(T) is larger than chunk size in std::deque<T>?
As far as I know, almost all the std::deque implementation in C++ is based on a list of fixed chunks.
Since the chunk is fixed size, I'm thinking what if sizeof(T) is larger than the chunk size? Will ...
1
vote
1answer
27 views
How can we add element to map<int,int>… so that they are stored in non increasing order in map
How can I make std::map<int,int> sorting values in non increasing order ?
map<int,int> mp;
mp[5]=7; // {5->7}
mp[3]=9; // {5->7,3->9}
mp[4]=9; // {5->7,4->9,3->9}
0
votes
1answer
33 views
Offset is outside the bounds of the DataView Error when loading .STL model in Angular 9
I want to add a 3d model view on my website using the stl-model-viewer described below:
https://www.npmjs.com/package/angular-stl-model-viewer
But I can't make it working. I went through the ...
0
votes
0answers
16 views
for_each statement and its printing [duplicate]
#include <iostream>
#include <deque>
#include <algorithm>
using namespace std;
template<class T>struct Out
{
ostream& out;
Out(ostream& o):out(o){}
void ...
0
votes
0answers
19 views
Count units from .STL file
I have to create an API that can accept a file in .stl format and return the number of units from the received file. From the attached image, the API has to return number 3.
After reading the .stl ...
0
votes
1answer
53 views
warning: decomposition declaration only available with -std=c++1z or -std=gnu++1
I've got this warning:
warning: decomposition declaration only available with -std=c++1z or -std=gnu++1
for this code:
#include<algorithm>
#include<vector>
int main(){
std::vector<...
-1
votes
1answer
19 views
how can we add an element in the map of set…eg .map<int,unordered_multiset<int>>mp; in c++14
i want add an element to the mp[x].
map<int,unordered_multiset>adj;
for(int i=0;i<n;i++)
{
cin>>brr[i];
if(brr[i]!=arr[i])
{
// i want to add an element
//in mp[brr[...
0
votes
0answers
19 views
Deprication in the statement in the vector [duplicate]
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
template <class T> struct Out
{
ostream& out;
Out(...
0
votes
0answers
14 views
How to choose t.widow for STL decomposition?
I have month wise data of disease cases (2016-2020). I calculated incidence for each month (cases/population). I used code STL(my data, s.window ="periodic") , based on review I have ...
0
votes
1answer
61 views
C++ Using container as a template type
I am trying to supply the underlying container/data structure for a class via template argument. I'd like to have the underlying container always contain a certain pointer type and I want the maximum ...
0
votes
1answer
46 views
C++ unordered_set<insert function> return value
I am trying to check return value of unordered_set's insert() function, but stuck with below error:
unordered_set<int> t;
t.insert(1);
t.insert(2);
t.insert(3);
t.insert(4);
std::unordered_set&...
0
votes
0answers
30 views
Operator Overloading and ostream in the class
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
class B
{
int val;
public:
B(int v):val(v){}
int getV() const {return val;}
bool ...