//g++ 4.9.3#include <iostream>#include <functional>class loader{ using progress = std::function<bool(float)>;public: template<class F> loader(F&& callback) :m_callbak( std::forward<F>(callback)) {} void load(const size_t size) { sumulateLoading_(size); } private: void sumulateLoading_(const size_t size) { if(!m_callbak) return std::cout <<"loading finished!\n", void(); const auto total = static_cast<float>(size); for(size_t n=0; n<size; ++n) if(!m_callbak( n*100/total )) return std::cout <<"loading abort!\n", void(); std::cout <<"loading finished!\n"; } private: progress m_callbak; };int main(){ std::cout << "Hello, world!\n"; const auto callback = [](const float v){ std::cout <<"loading ... "<<v << "%\n"; return v<90.0; }; loader(callback).load(10);}