Namespaces
Variants

C++ keyword: long

From cppreference.net
C++ language
General topics
Flow control
Conditional execution statements
Iteration statements (loops)
Jump statements
Functions
Function declaration
Lambda function expression
inline specifier
Dynamic exception specifications ( until C++17* )
noexcept specifier (C++11)
Exceptions
Namespaces
Types
Specifiers
constexpr (C++11)
consteval (C++20)
constinit (C++20)
Storage duration specifiers
Initialization
Expressions
Alternative representations
Literals
Boolean - Integer - Floating-point
Character - String - nullptr (C++11)
User-defined (C++11)
Utilities
Attributes (C++11)
Types
typedef declaration
Type alias declaration (C++11)
Casts
Memory allocation
Classes
Class-specific function properties
Special member functions
Templates
Miscellaneous

使用方法

#include <climits>
#include <concepts>
#include <iostream>
#include <limits>
#include <locale>
static_assert(
    sizeof(long) >= 32 / CHAR_BIT &&
    sizeof(unsigned long) >= 32 / CHAR_BIT &&
    std::numeric_limits<long>::min() <= -2'147'483'647l - 1 && //'
    std::numeric_limits<long>::max() >= 2'147'483'647l && //'
    std::numeric_limits<unsigned long>::max() >= 4'294'967'295ul); //'
// 'long long' および 'unsigned long long' は C++11 以降で利用可能
static_assert(
    sizeof(long long) >= 64 / CHAR_BIT &&
    sizeof(unsigned long long) >= 64 / CHAR_BIT &&
    std::numeric_limits<long long>::min() <= -9'223'372'036'854'775'807ll - 1 &&
    std::numeric_limits<long long>::max() >= 9'223'372'036'854'775'807ll &&
    std::numeric_limits<unsigned long long>::max() >= 18'446'744'073'709'551'615ull);
// concepts は C++20 以降で利用可能
static_assert(
    std::integral
(注:指定された条件に基づき、HTMLタグ・属性は保持し、C++固有用語は翻訳せず、タグ内のテキストもそのまま維持しました)<long> &&
    std::integral<long long> &&
    std::integral
(注:指定された条件に基づき、HTMLタグ・属性は一切翻訳せず、C++固有用語も翻訳していません。表示テキスト「std::integral」はC++標準ライブラリのコンセプト名であるため、原文のまま保持しています)<unsigned long> &&
    std::integral<unsigned long long> &&
    std::floating_point<long double>);
// 'long' は 'float' を修飾できないことに注意
static_assert(
    std::same_as<decltype(0l), signed long int> &&
    std::same_as<decltype(0ll), signed long long int> &&
    std::same_as<decltype(0ul), unsigned long int> &&
    std::same_as<decltype(0ull), unsigned long long int> &&
    std::same_as<decltype(0.l), long double>);
template <typename T, typename... Ts>
concept all_same = (... and std::same_as <T, Ts>);
static_assert(
    all_same<long, long int, signed long, signed long int> &&
    all_same<unsigned long, unsigned long int> &&
    all_same<long long, long long int, signed long long, signed long long int> &&
    all_same<unsigned long long, unsigned long long int>);
#define OUT(...) std::cout << #__VA_ARGS__ << " = " << __VA_ARGS__ << '\n'
int main()
{
    std::cout.imbue(std::locale("en_US.UTF-8"));
    OUT(sizeof(long));
    OUT(std::numeric_limits<long>::min());
    OUT(std::numeric_limits<long>::max());
    OUT(std::numeric_limits<unsigned long>::max());
    OUT(sizeof(long long));
    OUT(std::numeric_limits<long long>::min());
    OUT(std::numeric_limits<long long>::max());
    OUT(std::numeric_limits<unsigned long long>::max());
}
#undef OUT

出力例:

sizeof(long) = 8
std::numeric_limits<long>::min() = -9,223,372,036,854,775,808
std::numeric_limits<long>::max() = 9,223,372,036,854,775,807
std::numeric_limits<unsigned long>::max() = 18,446,744,073,709,551,615
sizeof(long long) = 8
std::numeric_limits<long long>::min() = -9,223,372,036,854,775,808
std::numeric_limits<long long>::max() = 9,223,372,036,854,775,807
std::numeric_limits<unsigned long long>::max() = 18,446,744,073,709,551,615
**注記**: 指定された要件に従い、HTMLタグ、属性、 タグ内のテキスト、C++固有の用語は翻訳せず、元のフォーマットを保持しています。数値データとC++コードはそのまま維持されています。

関連項目