最終更新日時(UTC):
が更新

履歴 編集

リテラル演算子のスペースを省略可能とする(C++14)

概要

リテラル演算子を定義する際に、これまでは以下のように、operator""とサフィックス名の間に、ひとつ以上のスペースが必要だった。

ReturnType operator"" _suffix(const char*);

このスペースが不要となった:

ReturnType operator""_suffix(const char*); // OK

#include <iostream>
#include <string>

namespace my_namespace {
inline namespace literals {
  std::string operator""_s(const char* str, std::size_t length)
  {
    return std::string(str, length);
  }
}}

int main()
{
  using namespace my_namespace::literals;

  auto x = "hello"_s; // xの型はstd::string
  std::cout << x << std::endl;
}

出力

hello

関連項目

参照