C++ で std::tuple を使ってバージョン番号を比較する
元ネタ:C++ バージョン番号を比較する方法 - イネマルのプログラミング備忘録
#include <tuple> #include <iostream> int main(){ // 適当なバージョンデータ auto appA = std::tuple{ 2, 0, 101, 2 }; auto appB = std::tuple{ 2, 0, 100, 3 }; // C++11 で使いたいなら std::make_tuple を使う // auto appA = std::make_tuple(2, 0, 101, 2); // auto appB = std::make_tuple(2, 0, 100, 3); // 比較(appA < appB) bool result = appA < appB; // 結果 if (result) { std::cout << "appAの方が古い" << std::endl; } else { std::cout << "appBの方が古い" << std::endl; } return 0; } /* output: appBの方が古い */
こういう場合は std::tuple
便利だよね!!!といいたかっただけの記事。