LoginSignup
1
1

More than 5 years have passed since last update.

C++でも愛が生まれた

Last updated at Posted at 2016-05-09

元ネタ: http://qiita.com/dongri/items/041ff3e7dde6c99beeb0

#include <iostream>
#include <codecvt>
#include <locale>

int main()
{
    std::cout << std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t>().to_bytes(U'生' & U'死') << std::endl;
}

ここから確認できます
http://ideone.com/0lPZ8J

u8"生"u8"死" (どっちも char[4]) を要素毎に & 演算できれば、なかなか実装されていない <codecvt> とか使う必要がなかったのですが、ワンライナーでうまいこと書けなかったのでこんな感じになりました。
当初、std::transform を使おうとしてたのですが、範囲の終端や変換結果の格納先を指定する必要があるから、そのための変数を宣言しておく必要があるので。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1