프로그래밍/Morden C++

ddd

MAKGA 2023. 6. 28. 12:23
320x100
struct stst
{
	std::vector<int> vec;
};

std::vector<stst> vec;

template<typename... Args>
stst* findFunc(Args... args)
{
	auto iter = std::find_if(vec.begin(), vec.end(), [args = std::initializer_list<int>{ args... }](const stst& _st) {
		std::size_t argSize = args.size();

		if (_st.vec.size() < argSize)
		{
			return false;
		}

		for (std::size_t i = 0; i < argSize; ++i)
		{
			if (_st.vec[i] != *(args.begin() + i)) {
				return false;
			}
		}
		
		return true;
	});

	if (vec.end() == iter)
	{
		return nullptr;
	}

	return &(*iter);
}


int main()
{
	stst s1, s2, s3;
	s1.vec = { 0, 1, 2, 3 };
	s2.vec = { 4, 5, 6 };
	s3.vec = { 1, 2, 3 };

	vec.push_back(s1);
	vec.push_back(s2);
	vec.push_back(s3);

	auto ptr = findFunc(0, 1, 2, 3);
	if (nullptr != ptr)
	{
		for (auto iter : ptr->vec)
		{
			std::cout << iter << std::endl;
		}
	}

    return 0;
}
320x100