这是我尝试编译的代码的简短版本.
#include <iostream>
#include <functional>
#include <memory>
void foo(std::shared_ptr<int> b, unsigned int i)
{
std::cout << *b << " - " << i << std::endl;
}
int main()
{
using namespace std::placeholders;
typedef std::function<void(std::shared_ptr<int> b, unsigned int i)> Foo;
typedef std::function<void(unsigned int code)> Bar;
Foo f1 = foo;
Bar f2 = std::bind(f1, std::make_shared<int>(10), _1);
f2(0);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
g++-4.7 --version 给出g ++ - 4.7(GCC)4.7.1
g++-4.7 -std=c++11 test.cpp && ./a.out
10 - 0
Run Code Online (Sandbox Code Playgroud)
c++ --version 给出了Apple clang 4.0版(标签/ Apple/clang-421.0.60)(基于LLVM 3.1svn)
c++ …Run Code Online (Sandbox Code Playgroud) 我尝试将提升转换local_date_time为UTC,但我对utc_time()的返回时间感到困惑.这是一个简化的代码:
#include "boost/date_time/local_time/local_time.hpp"
int main()
{
using namespace boost::gregorian;
using namespace boost::local_time;
using namespace boost::posix_time;
ptime dt = ptime(date(2015, Mar, 2), hours(0));
time_zone_ptr tz_cet(new boost::local_time::posix_time_zone("CET"));
local_date_time local_dt = boost::local_time::local_date_time(dt, tz_cet);
std::cout << local_dt << std::endl;
std::cout << local_dt.utc_time() << std::endl;
time_zone_ptr tz_utc(new boost::local_time::posix_time_zone("UTC"));
std::cout << local_dt.local_time_in(tz_utc) << std::endl;
}
Run Code Online (Sandbox Code Playgroud)
输出:
2015-Mar-02 00:00:00 CET
2015-Mar-02 00:00:00
2015-Mar-02 00:00:00 UTC
Run Code Online (Sandbox Code Playgroud)
UTC应该比CET(中欧时间)晚1小时.
这是一个错误还是我错过了什么?
我正试图找到一种优雅的方式来找到一些文本ex."hello world"从句子"I compiled my first hello world. It works!"
但这句话std::list<word>带有一些元数据.
Class Word
{
std::string m_word;
Location ... (X,Y in a picture)
....
}
Run Code Online (Sandbox Code Playgroud)
只是想知道是否有一些很好的方法来做一些std或boost函数而不是我的2个丑陋的循环.谢谢!