프로그래밍/코드 조각
-
1:1 elo 레이팅 계산프로그래밍/코드 조각 2017. 12. 5. 15:58
#include #include int main(){ constexpr float K = 32; // K-factor and basically a measure of how strong a match will impact the players’ ratings. float rating1 = 2400; float rating2 = 2000; float R1 = std::pow(10, rating1/400); float R2 = std::pow(10, rating2/400); float E1 = R1 / (R1+R2); float E2 = R2 / (R1+R2); // match result // win:1, draw:0.5, lose:0 int res1 = 0; int res2 = 1; float new_r..
-
c++17 std::transform과 구조화된 바인딩 예제프로그래밍/코드 조각 2017. 12. 4. 13:21
#include #include #include #include #include int main(){ std::vector a{ 1,2,3,4,5 }; std::vector b{ "6", "7", "8", "9", "10" }; std::vector c; std::transform(a.begin(), a.end(), b.begin(), std::back_inserter(c), [](auto a, auto b) { return std::make_tuple(a, b); }); for (auto v : c) { auto [x, y] = v; std::cout
-
c++ 튜플 순회하기 예제프로그래밍/코드 조각 2017. 12. 1. 19:15
#include #include #include template void tuple_for_each_impl(const T& t, Func f, std::index_sequence){ (f(std::get(t)), ...);} template void tuple_for_each(std::tuple& t, Func f){ tuple_for_each_impl(t, f, std::index_sequence_for{});} int main(){ auto t = std::make_tuple(1, "name", 3.2f); tuple_for_each(t, [](auto v)..
-
-
Parse std::string with boost ptree프로그래밍/코드 조각 2016. 6. 16. 01:53
1234567891011121314151617181920212223#include #include #include #include #include namespace pt = boost::property_tree; std::string ss = "{ \"item1\" : 123, \"item2\" : 456, \"item3\" : 789 }"; int main(){ // Read json. pt::ptree pt2; boost::iostreams::array_source as(&ss[0], ss.size()); boost::iostreams::stream is(as); pt::read_json(is, pt2); std::cout