Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a quick way to create a set?

Tags:

c++

set

stl

Currently I'm creating a new set like this:

    std::set<A> s;
    s.insert(a1);
    s.insert(a2);
    s.insert(a3);
    ...
    s.insert(a10);

Is there a way to create s in one line?

like image 902
Amir Rachum Avatar asked Nov 16 '10 11:11

Amir Rachum


People also ask

How do you create sets?

Navigate to the Data pane, under Dimensions, right-click a field and select Create > Set. In the Create Set dialogue box, configure your set. You can configure your set using the following tabs; Use the General tab to select one or more values that will be considered when computing the set.

How do you create an empty set?

To create an empty set you have to use set(), not {}; the latter creates an empty dictionary, a data structure that we discuss in the next section.

How many ways can you create a set in Python?

There are two main methods to create sets. One is using the set function and the other is to use curly braces and add objects individually.


1 Answers

int myints[]= {10,20,30,40,50};
std::set<int> mySet(myints, myints + 5);

Ok, admittedly two lines :)

like image 128
Moo-Juice Avatar answered Sep 28 '22 04:09

Moo-Juice