当前位置: 首页>>代码示例>>C++>>正文


C++ set::contains方法代码示例

本文整理汇总了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;
		}
开发者ID:achiever202,项目名称:Assignments,代码行数:16,代码来源:set_implementation.cpp

示例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;
		}
开发者ID:achiever202,项目名称:Assignments,代码行数:18,代码来源:set_implementation.cpp

示例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;
		}
开发者ID:achiever202,项目名称:Assignments,代码行数:18,代码来源:set_implementation.cpp

示例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);
}
开发者ID:achiever202,项目名称:Assignments,代码行数:28,代码来源:set_implementation.cpp

示例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);
开发者ID:Alcaro,项目名称:Arlib,代码行数:31,代码来源:set-test.cpp


注:本文中的set::contains方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。