{"id":13730449,"url":"https://github.com/willwray/enum_traits","last_synced_at":"2025-05-08T03:30:39.823Z","repository":{"id":170414168,"uuid":"195283152","full_name":"willwray/enum_traits","owner":"willwray","description":"Type traits for properties of C / C++ enum types","archived":false,"fork":false,"pushed_at":"2019-07-09T15:37:11.000Z","size":35,"stargazers_count":19,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-08-04T02:09:34.347Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/willwray.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"COPYING.LESSER","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2019-07-04T17:58:46.000Z","updated_at":"2024-07-10T07:03:54.000Z","dependencies_parsed_at":"2024-01-31T01:16:07.986Z","dependency_job_id":null,"html_url":"https://github.com/willwray/enum_traits","commit_stats":null,"previous_names":["willwray/enum_traits"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willwray%2Fenum_traits","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willwray%2Fenum_traits/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willwray%2Fenum_traits/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willwray%2Fenum_traits/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/willwray","download_url":"https://codeload.github.com/willwray/enum_traits/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224695506,"owners_count":17354423,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T02:01:15.025Z","updated_at":"2024-11-14T21:30:59.868Z","avatar_url":"https://github.com/willwray.png","language":"C++","readme":"# **`enum_traits`** and **`enumerator_traits`**\n\n## **`enum_traits`** for properties of C / C++ enum types\n\n\u003e C++17. Targets GCC \u0026 Clang (MSVC is WIP). Namespace `ltl`.\n\n\u003cdetails\u003e\u003csummary\u003eCopyright \u0026copy; 2019 Will Wray. Distributed under the Boost Software License, V1.0\u003c/summary\u003e\n\n### **Boost Software License** - Version 1.0 - August 17th, 2003\n\n```txt\nPermission is hereby granted, free of charge, to any person or organization\nobtaining a copy of the software and accompanying documentation covered by\nthis license (the \"Software\") to use, reproduce, display, distribute,\nexecute, and transmit the Software, and to prepare derivative works of the\nSoftware, and to permit third-parties to whom the Software is furnished to\ndo so, all subject to the following:\n\nThe copyright notices in the Software and this entire statement, including\nthe above license grant, this restriction and the following disclaimer,\nmust be included in all copies of the Software, in whole or in part, and\nall derivative works of the Software, unless such copies or derivative\nworks are solely in the form of machine-executable object code generated by\na source language processor.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT\nSHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE\nFOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,\nARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\nDEALINGS IN THE SOFTWARE.\n```\n\n[![License](https://img.shields.io/badge/license-boost%201.0-blue.svg)](https://www.boost.org/LICENSE_1_0.txt)\n\nAlso at [boost.org](http://www.boost.org/LICENSE_1_0.txt) and accompanying file [LICENSE_1_0.txt](LICENSE_1_0.txt)\n\n\u003c/details\u003e\n\n```C++\n  ltl::is_scoped_enum\u003cT\u003e;    // Test if type T is a scoped enum (lazy).\n  ltl::is_scoped_enum_v\u003cT\u003e;  // Test if type T is a scoped enum (eager).\n\n  ltl::is_fixed_enum\u003cT\u003e;     // Test if type T is a 'fixed' enum,\n  ltl::is_fixed_enum_v\u003cT\u003e;   // i.e. an enum  with fixed underlying type.\n\n  ltl::underlying_type\u003cT\u003e;   // c++17 port of c++20's improved UB-free\n  ltl::underlying_type_t\u003cT\u003e; // 'SFINAE-friendly' std::underlying_type.\n\n  ltl::to_underlying(e);     // Convenience cast to underlying type P1682.\n```\n\n## **`enumerator_traits`** for reflection of enumerated values\n\n\u003e C++17. Targets GCC\u003e=9 and Clang (recent MSVC possible). Namespace `ltl`.\n\n\u003cdetails\u003e\u003csummary\u003eCopyright \u0026copy; 2019 Will Wray. Distributed under LGPL-3.0-or-later.\u003c/summary\u003e\n\n```txt\n                   GNU LESSER GENERAL PUBLIC LICENSE\n                       Version 3, 29 June 2007\n\n Copyright (C) 2007 Free Software Foundation, Inc. \u003chttps://fsf.org/\u003e\n Everyone is permitted to copy and distribute verbatim copies\n of this license document, but changing it is not allowed.\n\n\n  This version of the GNU Lesser General Public License incorporates\nthe terms and conditions of version 3 of the GNU General Public\nLicense, supplemented by the additional permissions listed below.\n\n  0. Additional Definitions.\n\n  As used herein, \"this License\" refers to version 3 of the GNU Lesser\nGeneral Public License, and the \"GNU GPL\" refers to version 3 of the GNU\nGeneral Public License.\n\n  \"The Library\" refers to a covered work governed by this License,\nother than an Application or a Combined Work as defined below.\n\n  An \"Application\" is any work that makes use of an interface provided\nby the Library, but which is not otherwise based on the Library.\nDefining a subclass of a class defined by the Library is deemed a mode\nof using an interface provided by the Library.\n\n  A \"Combined Work\" is a work produced by combining or linking an\nApplication with the Library.  The particular version of the Library\nwith which the Combined Work was made is also called the \"Linked\nVersion\".\n\n  The \"Minimal Corresponding Source\" for a Combined Work means the\nCorresponding Source for the Combined Work, excluding any source code\nfor portions of the Combined Work that, considered in isolation, are\nbased on the Application, and not on the Linked Version.\n\n  The \"Corresponding Application Code\" for a Combined Work means the\nobject code and/or source code for the Application, including any data\nand utility programs needed for reproducing the Combined Work from the\nApplication, but excluding the System Libraries of the Combined Work.\n\n  1. Exception to Section 3 of the GNU GPL.\n\n  You may convey a covered work under sections 3 and 4 of this License\nwithout being bound by section 3 of the GNU GPL.\n\n  2. Conveying Modified Versions.\n\n  If you modify a copy of the Library, and, in your modifications, a\nfacility refers to a function or data to be supplied by an Application\nthat uses the facility (other than as an argument passed when the\nfacility is invoked), then you may convey a copy of the modified\nversion:\n\n   a) under this License, provided that you make a good faith effort to\n   ensure that, in the event an Application does not supply the\n   function or data, the facility still operates, and performs\n   whatever part of its purpose remains meaningful, or\n\n   b) under the GNU GPL, with none of the additional permissions of\n   this License applicable to that copy.\n\n  3. Object Code Incorporating Material from Library Header Files.\n\n  The object code form of an Application may incorporate material from\na header file that is part of the Library.  You may convey such object\ncode under terms of your choice, provided that, if the incorporated\nmaterial is not limited to numerical parameters, data structure\nlayouts and accessors, or small macros, inline functions and templates\n(ten or fewer lines in length), you do both of the following:\n\n   a) Give prominent notice with each copy of the object code that the\n   Library is used in it and that the Library and its use are\n   covered by this License.\n\n   b) Accompany the object code with a copy of the GNU GPL and this license\n   document.\n\n  4. Combined Works.\n\n  You may convey a Combined Work under terms of your choice that,\ntaken together, effectively do not restrict modification of the\nportions of the Library contained in the Combined Work and reverse\nengineering for debugging such modifications, if you also do each of\nthe following:\n\n   a) Give prominent notice with each copy of the Combined Work that\n   the Library is used in it and that the Library and its use are\n   covered by this License.\n\n   b) Accompany the Combined Work with a copy of the GNU GPL and this license\n   document.\n\n   c) For a Combined Work that displays copyright notices during\n   execution, include the copyright notice for the Library among\n   these notices, as well as a reference directing the user to the\n   copies of the GNU GPL and this license document.\n\n   d) Do one of the following:\n\n       0) Convey the Minimal Corresponding Source under the terms of this\n       License, and the Corresponding Application Code in a form\n       suitable for, and under terms that permit, the user to\n       recombine or relink the Application with a modified version of\n       the Linked Version to produce a modified Combined Work, in the\n       manner specified by section 6 of the GNU GPL for conveying\n       Corresponding Source.\n\n       1) Use a suitable shared library mechanism for linking with the\n       Library.  A suitable mechanism is one that (a) uses at run time\n       a copy of the Library already present on the user's computer\n       system, and (b) will operate properly with a modified version\n       of the Library that is interface-compatible with the Linked\n       Version.\n\n   e) Provide Installation Information, but only if you would otherwise\n   be required to provide such information under section 6 of the\n   GNU GPL, and only to the extent that such information is\n   necessary to install and execute a modified version of the\n   Combined Work produced by recombining or relinking the\n   Application with a modified version of the Linked Version. (If\n   you use option 4d0, the Installation Information must accompany\n   the Minimal Corresponding Source and Corresponding Application\n   Code. If you use option 4d1, you must provide the Installation\n   Information in the manner specified by section 6 of the GNU GPL\n   for conveying Corresponding Source.)\n\n  5. Combined Libraries.\n\n  You may place library facilities that are a work based on the\nLibrary side by side in a single library together with other library\nfacilities that are not Applications and are not covered by this\nLicense, and convey such a combined library under terms of your\nchoice, if you do both of the following:\n\n   a) Accompany the combined library with a copy of the same work based\n   on the Library, uncombined with any other library facilities,\n   conveyed under the terms of this License.\n\n   b) Give prominent notice with the combined library that part of it\n   is a work based on the Library, and explaining where to find the\n   accompanying uncombined form of the same work.\n\n  6. Revised Versions of the GNU Lesser General Public License.\n\n  The Free Software Foundation may publish revised and/or new versions\nof the GNU Lesser General Public License from time to time. Such new\nversions will be similar in spirit to the present version, but may\ndiffer in detail to address new problems or concerns.\n\n  Each version is given a distinguishing version number. If the\nLibrary as you received it specifies that a certain numbered version\nof the GNU Lesser General Public License \"or any later version\"\napplies to it, you have the option of following the terms and\nconditions either of that published version or of any later version\npublished by the Free Software Foundation. If the Library as you\nreceived it does not specify a version number of the GNU Lesser\nGeneral Public License, you may choose any version of the GNU Lesser\nGeneral Public License ever published by the Free Software Foundation.\n\n  If the Library as you received it specifies that a proxy can decide\nwhether future versions of the GNU Lesser General Public License shall\napply, that proxy's public statement of acceptance of any version is\npermanent authorization for you to choose that version for the\nLibrary.\n```\n\n[![License: LGPL v3](https://img.shields.io/badge/License-LGPL%20v3-blue.svg)](https://www.gnu.org/licenses/lgpl-3.0)\n\nAlso at [gnu.org](https://www.gnu.org/licenses/lgpl-3.0) and accompanying file [COPYING.LESSER](COPYING.LESSER)\n\n\u003c/details\u003e\n\n----\n\n```C++\n  ltl::is_enumerated_v\u003ce\u003e; // Test if enum value e corresponds to an\n                           // enumerator of its enum type decltype(e).\n\n  ltl::enumerators_v\u003cE\u003e;   // Array of enumerated values of enum type E\n                           // (see note on duplicate-valued enumerators).\n  ltl::enumerators_t\u003cE\u003e;   // integer_sequence\u003cunderlying_type_t\u003cE\u003e,u...\u003e\n                           // of E's enumerators' underlying values u...\n  ltl::enumerators\u003cE\u003e;     // Trait class for enumerated values of E with\n                           // array 'value' and typedef 'type' members.\n```\n\nThe array returned by `enumerators_v` is of an internal type, sufficient\nto index,  \nrange-for iterate or copy into another container.\n\n## Description\n\nTwo header-only libraries of 'type traits'; template-based utilities to query:  \n\n1. **`enum_traits`** Properties of enum types\n2. **`enumerator_traits`** Enumerated values of an enum type\n\nThe traits interface is constexpr; runtime facilities can be built on top.  \nThese libraries deal only with enumerated *values*, not with *names* of ids.  \nReflection of names can be dealt with at a higher level.\n\n\u003e See the [example repo](https://github.com/willwray/enum_reflect) for full reflection of enum types, including names.\n\n----\n\n## Reflection of enumerated values\n\nA 'brute force' method is used to check possible values of the underlying type.  \nIt takes around a second to exhaustively check all 2^16 values of a 16-bit enum  \n(on a decent recent dev box - GCC faster than Clang, MSVC out of the game).\n\n### Support for `underlying_type` bit-widths\n\nEnum types with \u003c= **16-bit** underlying type are fully supported - exhaustive check  \nEnum types with **32-bit** underlying type are partially supported - far from exhaustive.\n\n### **32-bit** underlying type partial support\n\n2^16 values of the same-signed 16-bit integer are checked, plus:\n\n* for **uint32**, check 392 high values (`UINT16_MAX`, `UINT32_MAX`].\n* for **int32**, check 32 negative values [`INT32_MIN`, `INT16_MIN`)  \n  * and 360 high positive values (`INT16_MAX`, `INT32_MAX`].\n\nThe 32-bit `Int_MAX` high ranges comprise all values with a contiguous run of set bits.  \nThis means that 'flag enums' with contiguous bitfield / bitmask values are supported.\n\nEnum types with **64-bit** underlying type are unsupported, giving a compile error.\n\n----\n\n## Platform support\n\nGCC\u003e=9 is required for a bugfix (earlier versions can be patched).  \nMSVC is work in progress. 8-bit underlying value works.  \nC++17 for auto template parameters, constexpr if, inline variables...\n\n### Disclaimers\n\nEnumerator extraction uses non-standard 'pretty function' preprocessor  \nextensions whose output differs between compilers \u0026 compiler versions.  \nThis is not a future-proof solution. Use with caution.  \nTest for your use-case and target platforms.\n\n----\n\n## Build\n\nMeson build script provided, e.g. use with ninja backend\n\n```bash\nmeson build\nninja -C build\n```\n\n| Linux Travis| Windows Appveyor|\n| :---: | :---: |\n|gcc-9, clang-7\u003cbr\u003e-std=c++17|MSVC 19.21.27702.2\u003cbr\u003e/std:c++latest|\n| [![Build Status](https://travis-ci.org/willwray/enum_traits.svg?branch=master)](https://travis-ci.org/willwray/enum_traits) | [![Build status](https://ci.appveyor.com/api/projects/status/gc7js22t8v0e5u9s?svg=true)](https://ci.appveyor.com/project/willwray/enum-traits) |\n","funding_links":[],"categories":["C++"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwillwray%2Fenum_traits","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwillwray%2Fenum_traits","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwillwray%2Fenum_traits/lists"}