xtd - Reference Guide  0.1.2
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
Loading...
Searching...
No Matches
cpp_language.h
Go to the documentation of this file.
1
4#pragma once
5#include <cstdint>
6#include <map>
7#include <vector>
8#include "language_id.h"
9#include "object.h"
10#include "ustring.h"
11#include "version.h"
12
14namespace xtd {
24 class cpp_language final : public object {
25 public:
26 cpp_language(uint32_t cpp) : cpp_(cpp) {}
27
29 cpp_language() = default;
30 cpp_language(const cpp_language&) = default;
31 cpp_language& operator=(const cpp_language&) = default;
32 friend std::ostream& operator <<(std::ostream& os, const cpp_language& cpp_language) noexcept {return os << cpp_language.to_string();}
34
35 bool is_experimental_language() const noexcept {return language() != experimental_language();}
36
37 bool is_supported() const noexcept {return cpp_ >= 201703L;}
38
39 language_id language() const noexcept {
40 if (cpp_ >= 202002L) return language_id::cpp20;
41 if (cpp_ >= 201703L) return language_id::cpp17;
42 if (cpp_ >= 201402L) return language_id::cpp14;
43 if (cpp_ >= 201103L) return language_id::cpp11;
44 if (cpp_ >= 199711L) return language_id::cpp98;
45 if (cpp_ >= 1L) return language_id::cpp_pre98;
47 }
48
49 language_id experimental_language() const noexcept {
50 if (cpp_ >= 201707L) return language_id::cpp20;
51 if (cpp_ >= 201411L) return language_id::cpp17;
52 if (cpp_ >= 201210L) return language_id::cpp14;
53 if (cpp_ >= 200410L) return language_id::cpp11;
54 if (cpp_ >= 199711L) return language_id::cpp98;
55 if (cpp_ >= 1L) return language_id::cpp_pre98;
57 }
58
59 int32_t month() const noexcept {return cpp_ % 100;}
60
61 xtd::ustring name() const noexcept {
62 static std::map<language_id, xtd::ustring> names {{language_id::cpp_pre98, "C++ Pre 98"}, {language_id::cpp98, "C++ 98"}, {language_id::cpp11, "C++ 11"}, {language_id::cpp14, "C++ 14"}, {language_id::cpp17, "C++ 17"}, {language_id::cpp20, "C++ 20"}, {language_id::unknown, "<unknown>"}};
63 if (is_experimental_language()) return ustring::format("Experimental {}", names[experimental_language()]);
64 return names[language()];
65 }
66
67 uint32_t value() const noexcept {return cpp_;}
68
69 xtd::ustring version_string() const noexcept {
70 return ustring::format("{} {}", name(), version());
71 }
72
73 const xtd::version& version() const noexcept {
74 static xtd::version ver(cpp_/100, cpp_%100);
75 return ver;
76 }
77
78 int32_t year() const noexcept {return cpp_ / 100;}
79
82 xtd::ustring to_string() const noexcept {return version_string();}
83
84 private:
85 uint32_t cpp_ = __cplusplus;
86 };
87}
Represents information about c++ libraries, such as the version and language identifier....
Definition cpp_language.h:24
xtd::ustring to_string() const noexcept
Converts the value of this operating_system object to its equivalent string representation.
Definition cpp_language.h:82
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.h:26
Represents text as a sequence of UTF-8 code units.
Definition ustring.h:48
Represents the version number of an assembly, operating system, or the xtd. This class cannot be inhe...
Definition version.h:93
static ustring format(const ustring &fmt, args_t &&... args)
Writes the text representation of the specified arguments list, to string using the specified format ...
Definition ustring.h:689
language_id
Identifies the c++ language used by assembly.
Definition language_id.h:16
@ cpp14
The language is c++14.
@ cpp98
The language is c++98.
@ cpp20
The language is c++20.
@ cpp_pre98
The language is pre 98.
@ unknown
The language is unknown.
@ cpp11
The language is c++11.
@ cpp17
The language is c++17.
Contains xtd::language_id enum class.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition system_report.h:17
Contains xtd::object class.
Contains xtd::ustring class.
Contains xtd::version class.