예제 #1
0
typename T2::iterator copy_safe_apart(size_t n, const T1 & tab_src, T2 & tab_dst, size_t offset_src=0, size_t offset_dst=0) {
	_dbg5("copy (tab) n="<<n);
	if (n<1) return tab_dst.begin();

	// could write both blocks below with lambda, in C++17TODO when decomposition declarations is available

	// source
	auto src_rb = tab_src.begin() + offset_src; // rb = range begin
	_check_input( offset_src < tab_src.size() );
	_check_input( n <= tab_src.size() - offset_src ); // subtracting offset_src is valid since above
	auto src_rl = tab_src.begin() + offset_src + n -1; // range last
	_dbg5("Source     range src_rb="<<to_debug(src_rb)<<" ... src_rl="<<to_debug(src_rl));
	_check_abort( src_rl <= tab_src.end() );

	// dest
	auto dst_rb = tab_dst.begin() + offset_dst; // rb = range begin
	_check_input( offset_dst < tab_dst.size() );
	_check_input( n <= tab_dst.size() - offset_dst ); // subtracting offset_dst is valid since above
	auto dst_rl = tab_dst.begin() + offset_dst + n -1; // range last
	_dbg5("Destintion range dst_rb="<<to_debug(dst_rb)<<" ... dst_rl="<<to_debug(dst_rl));
	_check_abort( dst_rl <= tab_dst.end() );

	bool overlap = test_ranges_overlap_inclusive_noempty(src_rb, src_rl,  dst_rb, dst_rl);
	_dbg5("overlap=" << overlap);
	_check_input(!overlap);

	copy_iter_and_check_no_overlap( src_rb, src_rl,  dst_rb, n );
	_dbg5("Copy done.");

	return dst_rb;
}
	result_type
	operator()(
		T1 const &_range1,
		T2 const &_range2
	) const
	{
		typename T2::iterator it2(
			_range2.begin()
		);

		typename T1::iterator const end1(
			_range1.end()
		);

		for(
			typename T1::iterator it1(
				_range1.begin()
			);
			it1 != end1;
			++it1, ++it2
		)
			fun_(
				*it1,
				*it2
			);
	}
예제 #3
0
void UpdateItem(WORD32 dwKey, T2 &vec, T1 *pData)
{
	T1 *pInfo = NULL;
	SNMP_PERF_VEC_IT it;
	for(it = vec.begin(); it != vec.end(); it++)
	{
		if((*it).dwKey == dwKey)
		{
			pInfo = &(*it);
			check_paranullpt(pInfo);
			memset(pInfo, 0, sizeof(*pInfo));
			memcpy(pInfo, pData, sizeof(*pInfo));
			printf("updateitem, update data, key:%#x\n", dwKey);
			return;
		}
	}
	
	// pInfo = new T1();
	pInfo = &g_snmptest;
	check_paranullpt(pInfo);
	memset(pInfo, 0, sizeof(*pInfo));
	memcpy(pInfo, pData, sizeof(*pInfo));
	vec.push_back(*pInfo);
	printf("updateitem, create data, key:%#x, new addr:%p\n", dwKey, pInfo);

}
예제 #4
0
void insertSort( T1& nums, T2& vecnum)
{
	for(auto lit = nums.begin(); lit!=nums.end(); lit++)
	{
		if(vecnum.size()==0) vecnum.push_back(*lit);
		else
		{
			auto vit = vecnum.begin(); //vector iterator
			while(*vit<*lit && vit!=vecnum.end())
				vit++;
			vecnum.insert(vit, *lit);
		}
	}
}
예제 #5
0
typename T1::ScalarType scalarProduct(const T1& v1,const T2& v2)
{
  if(v1.dimension()!=v2.dimension())
    throw std::range_error("chomp::vectalg::scalarProduct: Incompatible dimensions");
  typename T1::ScalarType result(0);
  typename T1::const_iterator b1=v1.begin();
  typename T2::const_iterator b2=v2.begin(), e2=v2.end();
  while(b2!=e2)
  {
    result += (*b1) * (*b2);
    ++b1;
    ++b2;
  }
  return result;
}
예제 #6
0
bool equal (const T1& v1, const T2& v2)
{
  if(v1.dimension()!=v2.dimension())
    throw std::range_error("chomp::vectalg::equal: Incompatible dimensions");
  typename T1::const_iterator b1=v1.begin(), e1=v1.end();
  typename T2::const_iterator b2=v2.begin();
  
  while(b1!=e1)
  {
    if(!(*b1 == *b2))
       return false;
    ++b1;
    ++b2;
  }
  return true;
}
예제 #7
0
void RemoveItem(WORD32 dwKey, T2 &vec)
{
	T1 *pInfo = NULL;
	SNMP_PERF_VEC_IT it;
	for(it = vec.begin(); it != vec.end(); it++)
	{
		if((*it).dwKey == dwKey)
		{
			pInfo = &(*it);
			check_paranullpt(pInfo);
			vec.erase(it);
			printf("removeitem, remove ok, key:%#x\n", dwKey);
			return;
		}
	}
	printf("removeitem, no data, key:%#x\n", dwKey);
}
예제 #8
0
ResultType subtractObjects(const T1& v1,const T2& v2)
{
  if(v1.dimension()!=v2.dimension())
    throw std::range_error("chomp::vectalg::subtractObjects: Incompatible dimensions");
  ResultType result(v1.dimension(),true);
  typename ResultType::iterator b=result.begin(), e=result.end();
  typename T1::const_iterator b1=v1.begin();
  typename T2::const_iterator b2=v2.begin();
  while(b!=e)
  {
    *b = (*b1) - (*b2);
    ++b;
    ++b1;
    ++b2;
  }
  return result;
}
예제 #9
0
template <typename T1, typename T2> void merge_exception_test(T1 x, T2 y)
{
    std::size_t size = x.size() + y.size();

    try {
        ENABLE_EXCEPTIONS;
        x.merge(y);
    } catch (...) {
        test::check_equivalent_keys(x);
        test::check_equivalent_keys(y);
        throw;
    }

    // Not a full check, just want to make sure the merge completed.
    BOOST_TEST(size == x.size() + y.size());
    if (y.size()) {
        BOOST_TEST(test::has_unique_keys<T1>::value);
        for (typename T2::iterator it = y.begin(); it != y.end(); ++it) {
            BOOST_TEST(x.find(test::get_key<T2>(*it)) != x.end());
        }
    }
    test::check_equivalent_keys(x);
    test::check_equivalent_keys(y);
}
예제 #10
0
::iutest::AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperEqRange(const char* expected_expr, const char* actual_expr
    , const ::std::initializer_list<T1>& expected, const T2& actual)
{
    return detail::CmpHelperEqRange(expected_expr, actual_expr, expected.begin(), expected.end()
        , actual.begin(), actual.end());
}
예제 #11
0
::iutest::AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperEqRange(const char* expected_expr, const char* actual_expr
    , T1(&expected)[SIZE1], const T2& actual)
{
    return detail::CmpHelperEqRange(expected_expr, actual_expr, expected, expected+SIZE1
        , actual.begin(), actual.end());
}