コード例 #1
0
ファイル: ucompos2.cpp プロジェクト: stormbrew/stir
int ucompos2_test(int, char**)
{
  std::cout<<"Results of ucompos2_test:"<<std::endl;

int input [3] = { -1, -4, -16 };

  int output [3];
  std::transform((int*)input, (int*)input + 3, (int*)output, 
    compose1(square_root(), negate<int>()));
  for(int i = 0; i < 3; i++)
   std::cout << output[i] << std::endl;
  return 0;
}
コード例 #2
0
ファイル: select2nd.cpp プロジェクト: IMCG/cpptruths
int main(void) 
{
  mymap m;
  for(int i = 0; i < 5; ++i )
    m[i] = i;

  // 'remove' all elements from map where .second < 3
  //std::remove_if(m.begin(), m.end(), 
                 //compose1(std::bind2nd(std::less<int>(), 3), select2nd<mymap::value_type>()));
                 //boost::bind(&std::pair<int,unsigned>::second, _1) < 3);
                 //foo);
  std::cout << "Count = " 
            << std::count_if(m.begin(), m.end(), 
               compose1(std::bind2nd(std::less<int>(), 3), select2nd<mymap::value_type>()))
               // foo)
            << std::endl;
  
#ifdef __GXX_EXPRERIMENTAL_CXX0X_
  std::remove_if(m.begin(), m.end(), [](const mymap::value_type & p) { return p.second < 3; } );
#endif // __GXX_EXPRERIMENTAL_CXX0X_
  
  const mymap & cm = m;
  std::transform(cm.begin(), 
                 cm.end(), 
                 std::ostream_iterator<unsigned>(std::cout," "),
                 select2nd<mymap::value_type>());

  typedef boost::function<bool (const IntPair &, const IntPair &)> Comparator;
  Comparator c = boost::bind(&IntPair::second, _1) < boost::bind(&IntPair::second, _2);
  std::set<IntPair, Comparator> s(c);
  s.insert(IntPair(5,6));
  s.insert(IntPair(3,4));
  s.insert(IntPair(1,2));
  BOOST_FOREACH(IntPair const & p, s)
  {
    std::cout << p;
  }
コード例 #3
0
ファイル: ndaspnp.cpp プロジェクト: tigtigtig/ndas4windows
void
CNdasServiceDeviceEventHandler::Uninitialize()
{
	//if (m_bROFilterFilteringStarted) 
	//{
	//	BOOL fSuccess = NdasRoFilterStopFilter(m_hROFilter);
	//	if (fSuccess) 
	//	{
	//		m_bROFilterFilteringStarted = FALSE;
	//	}
	//	else
	//	{
	//		XTLTRACE2_ERR(NDASSVC_PNP, TRACE_LEVEL_WARNING, "Failed to stop ROFilter session.\n");
	//		ret = false;
	//	}
	//}

	EnterCriticalSection(&m_DevNotifyMapSection);

	std::for_each(
		m_DevNotifyMap.begin(),
		m_DevNotifyMap.end(),
		compose1(
			DevNotifyHandleCloser(), 
			select1st<DevNotifyMap::value_type>()));

	m_DevNotifyMap.clear();

	std::for_each(
		m_DeviceInterfaceNotifyHandles.begin(),
		m_DeviceInterfaceNotifyHandles.end(),
		DevNotifyHandleCloser());

	m_DeviceInterfaceNotifyHandles.clear();

	LeaveCriticalSection(&m_DevNotifyMapSection);
}
コード例 #4
0
void Class::staticInitialization() {
	std::for_each(__classes->begin(), __classes->end(), 
		compose1(std::ptr_fun(initializeOnce),
		select2nd<ClassMap::value_type>()));
	m_isInitialized = true;
}
コード例 #5
0
ファイル: bvt10.cpp プロジェクト: houzhenggang/ecos-1
void TestFunctors (void)
{
    vector<int> v;
    v.resize (20);
    fill (v, 2);
    foreach (vector<int>::iterator, i, v)
        *i -= distance(v.begin(), i) & 1;
    vector<int> v1 (v);

    cout << "start:\t\t\t";
    PrintVector (v);

    v = v1;
    cout << "plus:\t\t\t";
    transform (v, v.begin(), v.begin(), plus<int>());
    PrintVector (v);

    v = v1;
    cout << "minus:\t\t\t";
    transform (v, v.begin(), v.begin(), minus<int>());
    PrintVector (v);

    v = v1;
    cout << "divides:\t\t";
    transform (v, v.begin(), v.begin(), divides<int>());
    PrintVector (v);

    v = v1;
    cout << "multiplies:\t\t";
    transform (v, v.begin(), v.begin(), multiplies<int>());
    PrintVector (v);

    v = v1;
    cout << "modulus:\t\t";
    transform (v, v.begin(), v.begin(), modulus<int>());
    PrintVector (v);

    v = v1;
    cout << "logical_and:\t\t";
    transform (v, v.begin(), v.begin(), logical_and<int>());
    PrintVector (v);

    v = v1;
    cout << "logical_or:\t\t";
    transform (v, v.begin(), v.begin(), logical_or<int>());
    PrintVector (v);

    v = v1;
    cout << "equal_to:\t\t";
    transform (v, v.begin(), v.begin(), equal_to<int>());
    PrintVector (v);

    v = v1;
    cout << "not_equal_to:\t\t";
    transform (v, v.begin(), v.begin(), not_equal_to<int>());
    PrintVector (v);

    v = v1;
    cout << "greater:\t\t";
    transform (v, v.begin(), v.begin(), greater<int>());
    PrintVector (v);

    v = v1;
    cout << "less:\t\t\t";
    transform (v, v.begin(), v.begin(), less<int>());
    PrintVector (v);

    v = v1;
    cout << "greater_equal:\t\t";
    transform (v, v.begin(), v.begin(), greater_equal<int>());
    PrintVector (v);

    v = v1;
    cout << "less_equal:\t\t";
    transform (v, v.begin(), v.begin(), less_equal<int>());
    PrintVector (v);

    v = v1;
    cout << "compare:\t\t";
    transform (v, v.begin(), v.begin(), compare<int>());
    PrintVector (v);

    v = v1;
    cout << "negate:\t\t\t";
    transform (v, negate<int>());
    PrintVector (v);

    v = v1;
    cout << "logical_not:\t\t";
    transform (v, logical_not<int>());
    PrintVector (v);

    v = v1;
    cout << "unary_neg(negate):\t";
    transform (v, unary_negator(negate<int>()));
    PrintVector (v);

    v = v1;
    cout << "binder1st(plus,5):\t";
    transform (v, bind1st(plus<int>(), 5));
    PrintVector (v);

    v = v1;
    cout << "binder2nd(minus,1):\t";
    transform (v, bind2nd(minus<int>(), 1));
    PrintVector (v);

    v = v1;
    cout << "compose1(-,+5):\t\t";
    transform (v, compose1 (negate<int>(), bind2nd(plus<int>(), 5)));
    PrintVector (v);

    v = v1;
    cout << "compose1(-,-4):\t\t";
    transform (v, compose1 (negate<int>(), bind2nd(minus<int>(), 4)));
    PrintVector (v);

    v = v1;
    cout << "compose2(/,+6,-4):\t";
    transform (v, compose2 (divides<int>(), bind2nd(plus<int>(), 6), bind2nd(minus<int>(), 4)));
    PrintVector (v);

    cout << "mem_var(plus,6):\t";
    vector<A> av;
    for (uoff_t i = 0; i < 20; ++ i)
        av.push_back (A(i));
    transform (av, mem_var1(&A::m_v, bind2nd(plus<int>(), 6)));
    PrintVector (av);

    vector<A>::iterator found = find_if (av, mem_var_equal_to(&A::m_v, 14));
    cout << "14 found at position " << found - av.begin() << endl;
    found = lower_bound (av.begin(), av.end(), 18, mem_var_less(&A::m_v));
    cout << "18 found at position " << found - av.begin() << endl;

    cout << "add next:\t\t";
    transform (av.begin(), av.end() - 1, av.begin() + 1, av.begin(), mem_var2(&A::m_v, plus<int>()));
    PrintVector (av);
}