public: staticboolconst value = sizeof(Test<T>(0)) == sizeof(Yes); };
template<bool B, classT = void> // Defaulttemplateversion. structenable_if {}; // This struct doesn't define "type" and the substitution will fail if you try to access it.
template<classT> // Aspecialisationusediftheexpressionistrue. structenable_if<true, T> {typedef T type; }; // This struct do have a "type" and won't fail on access.
template<typename T> concept have_value = requires(T a) { a.value; }; template<typename T> requires have_value<T> autoget_value(const T& a) { auto v = a.value; // do some thing return v; } intmain() { int b = 10; auto y = get_value(b); }
錯誤訊息如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
<source>:2:1: error: 'concept' does not name a type 2 | concept have_value = requires(T a) { | ^~~~~~~
<source>:2:1: note: 'concept' only available with '-fconcepts' <source>:7:1: error: 'requires' does not name a type 7 | requires have_value<T> | ^~~~~~~~
<source>: In function'int main()': <source>:18:12: error: 'get_value' was not declared in this scope 18 | auto y = get_value(b); | ^~~~~~~~~
module.exports = { parser: "@typescript-eslint/parser", // Specifies the ESLint parser extends: [ "plugin:@typescript-eslint/recommended"// Uses the recommended rules from the @typescript-eslint/eslint-plugin ], parserOptions: { ecmaVersion: 2018, // Allows for the parsing of modern ECMAScript features sourceType: "module"// Allows for the use of imports }, rules: { // Place to specify ESLint rules. Can be used to overwrite rules specified from the extended configs // e.g. "@typescript-eslint/explicit-function-return-type": "off", } };
module.exports = { parser: "@typescript-eslint/parser", // Specifies the ESLint parser extends: [ "plugin:@typescript-eslint/recommended", // Uses the recommended rules from the @typescript-eslint/eslint-plugin "prettier/@typescript-eslint", // Uses eslint-config-prettier to disable ESLint rules from @typescript-eslint/eslint-plugin that would conflict with prettier "plugin:prettier/recommended"// Enables eslint-plugin-prettier and eslint-config-prettier. This will display prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array. ], parserOptions: { ecmaVersion: 2018, // Allows for the parsing of modern ECMAScript features sourceType: "module"// Allows for the use of imports } };
static class StringUtilities { public static int WordCount(this string text) { return text.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Length; } } var text = "This is an example"; var count = text.WordCount();