// in C DIR* dir = opendir("."); if(NULL != dir) { strUCt dirent* de; for(; NULL != (de = readdir(dir)); ) { struct stat st; if( 0 == stat(de->d_name, &st) && S_IFREG == (st.st_mode & S_IFMT)) { remove(de->d_name); } } closedir(dir); } |
int arr[10]; … // initialize arr for(int i = 0; i < 10; ++i) { int value = arr[i]; … printf } |
for(std::vector<int>::iterator iter = v.begin(); iter != v.end(); ++iter) { … } |
foreach(i; v) { … } |
transform(…, boost::bind(std::plus<int>(), boost::bind(f, _1), boost::bind(f, _1)) ); |
struct Op { int Operator()(int a1, int a2) { return f(a1) + f(a2); } }; transform(…, Op()); |
transform(…, <>(a1, a2){ f(a1) + f(a2) }); Simple things should be simple! |
int weight1 = 0.3, weight2 = 0.6; transform(…, f(_1)*weight1 + f(_2)*weight2); |
int weight1 = 0.3, weight2 = 0.6; transform(…, <&>(_1, _2){ f(_1)*weight1 + f(_2)*weight2 } ); |
function<int(int, int)> caller = f; int r = caller(1, 2); // call f |
template<Signature> class function { operator()(???); }; |
template<typename R, typename T1> class function<R(T1)> { R operator()(T1 a1); }; template<typename R, typename T1, typename T2> class function<R(T1, T2)> { R operator()(T1 a1, T2 a2); }; template<typename R, typename T1, typename T2, typename T3> class function<R(T1, T2, T3)> { R operator()(T1 a1, T2 a2, T3 a3); }; … // 再写下去页宽不够了,打住… |
template<typename R, typename... Args> struct invoker_base { virtual R invoke(Args...) = 0; virtual ~invoker_base() { } }; template<typename F, typename R, typename... Args> struct functor_invoker : public invoker_base<R, Args...> { eXPlicit functor_invoker(F f) : f(f) { } R invoke(Args... args) { return f(args...); } private: F f; }; template<typename Signature> class function; template<typename R, typename... Args> class function<R (Args...)> { public: template<typename F> function(F f) : invoker(0) { invoker = new functor_invoker<F, R, Args...>(f); } R operator()(Args... args) const { return invoker->invoke(args...); } private: invoker_base<R, Args...>* invoker; }; |
template<class T1> cons(T1& t1, const null_type&, const null_type&, const null_type&, const null_type&, const null_type&, const null_type&, const null_type&, const null_type&, const null_type&) : head (t1) {} |
template<class R, class F, class A1, class A2, class A3, class A4, class A5, class A6> _bi::bind_t<R, F, typename _bi::list_av_6<A1, A2, A3, A4, A5, A6>::type> BOOST_BIND(boost::type<R>, F f, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) { typedef typename _bi::list_av_6<A1, A2, A3, A4, A5, A6>::type list_type; return _bi::bind_t<R, F, list_type>(f, list_type(a1, a2, a3, a4, a5, a6)); } |
新闻热点
疑难解答