本文整理汇总了C++中set::contains方法的典型用法代码示例。如果您正苦于以下问题:C++ set::contains方法的具体用法?C++ set::contains怎么用?C++ set::contains使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类set
的用法示例。
在下文中一共展示了set::contains方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: set_difference
/*
* This function takes the difference of a set with the current set (A-B).
* @param b: the set with which the difference operation is to be done (B).
* @return c: the set formed after the difference operation (A-B).
*/
set set_difference(set b)
{
set c;
/* for each member, checking if it is present in current set, and not in set b. */
for(int i=range_start; i<=range_end; i++)
if(contains(i) && !b.contains(i))
c.add(i);
return c;
}
示例2: set_intersection
/*
* This function takes the intersection of a set with the current set.
* @param b: the set with which the intersection operation is to be done.
* @return c: the set formed after the intersection operation.
*/
set set_intersection(set b)
{
set c;
/* for each number in range check if it is present in b and and in the current set, then add. */
for(int i=range_start; i<=range_end; i++)
{
if(b.contains(i) && contains(i))
c.add(i);
}
return c;
}
示例3: set_union
/*
* This function takes the union of a set with the current set.
* @param b: the set with which the union operation is to be done.
* @return c: the set formed after the union operation.
*/
set set_union(set b)
{
set c;
/* for each number in range check if it is present in b or in current set, then add. */
for(int i=range_start; i<=range_end; i++)
{
if(b.contains(i) || contains(i))
c.add(i);
}
return c;
}
示例4: write_set
/*
* This function writes the contents of a set to a file.
* @param filename: name of the file to be written to.
* @param s: set that has to be written to file.
* @return void: doesnt return anything.
*/
void write_set(string filename, set s)
{
int num;
/* Opening the given file. */
FILE *output = fopen(filename.c_str(), "w");
/* Error while opening file. */
if(output==NULL)
{
cout<<"ERROR: could not open file "<<filename<<".\n";
exit(0);
}
/* if the set contains a number in the range, write to file. */
for(int i=range_start; i<=range_end; i++)
if(s.contains(i))
fprintf(output, "%d\n", i);
/* closing the file. */
fclose(output);
}
示例5: hash
static int n_instancecount;
class instancecount {
public:
instancecount() { n_instancecount++; }
bool operator==(const instancecount& other) const { return true; }
size_t hash() const { return 0; }
};
test("set", "array", "set")
{
{
set<int> item;
uint32_t set_flags;
assert(!item.contains(1));
assert(!item.contains(2));
set_flags = 0;
for (int m : item) { assert(!(set_flags & (1<<m))); set_flags |= 1<<m; }
assert_eq(set_flags, 0);
item.add(1);
assert(item.contains(1));
assert(!item.contains(2));
set_flags = 0;
for (int m : item) { assert(!(set_flags & (1<<m))); set_flags |= 1<<m; }
assert_eq(set_flags, 1<<1);
item.add(2);