Skip to content

Commit

Permalink
wip v0.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Neargye committed Mar 20, 2019
1 parent e5fe425 commit 80a3e6d
Show file tree
Hide file tree
Showing 10 changed files with 175 additions and 498 deletions.
1 change: 0 additions & 1 deletion .appveyor.yml
Expand Up @@ -19,7 +19,6 @@ build:
environment:
matrix:
- GENERATOR: "Visual Studio 15 2017"
- GENERATOR: "Visual Studio 14 2015"

before_build:
- if exist build RMDIR /S /Q build
Expand Down
104 changes: 0 additions & 104 deletions .travis.yml
Expand Up @@ -9,50 +9,6 @@ git:

matrix:
include:
- os: linux
compiler: g++
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-4.8
env:
- CXX_COMPILER=g++-4.8 CC_COMPILER=gcc-4.8

- os: linux
compiler: g++
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-4.9
env:
- CXX_COMPILER=g++-4.9 CC_COMPILER=gcc-4.9

- os: linux
compiler: g++
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-5
env:
- CXX_COMPILER=g++-5 CC_COMPILER=gcc-5

- os: linux
compiler: g++
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-6
env:
- CXX_COMPILER=g++-6 CC_COMPILER=gcc-6

- os: linux
compiler: g++
addons:
Expand All @@ -75,66 +31,6 @@ matrix:
env:
- CXX_COMPILER=g++-8 CC_COMPILER=gcc-8

- os: linux
compiler: clang++
addons:
apt:
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-precise-3.6
packages:
- clang-3.6
env:
- CXX_COMPILER=clang++-3.6 CC_COMPILER=clang-3.6

- os: linux
compiler: clang++
addons:
apt:
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-precise-3.7
packages:
- clang-3.7
env:
- CXX_COMPILER=clang++-3.7 CC_COMPILER=clang-3.7

- os: linux
compiler: clang++
addons:
apt:
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-precise-3.8
packages:
- clang-3.8
env:
- CXX_COMPILER=clang++-3.8 CC_COMPILER=clang-3.8

- os: linux
compiler: clang++
addons:
apt:
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-trusty-3.9
packages:
- clang-3.9
env:
- CXX_COMPILER=clang++-3.9 CC_COMPILER=clang-3.9

- os: linux
compiler: clang++
addons:
apt:
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-trusty-4.0
packages:
- clang-4.0
env:
- CXX_COMPILER=clang++-4.0 CC_COMPILER=clang-4.0

- os: linux
compiler: clang++
addons:
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.6)

project(nameof VERSION "0.3.0" LANGUAGES CXX)
project(nameof VERSION "0.6.0" LANGUAGES CXX)

option(NAMEOF_OPT_BUILD_EXAMPLES "Build nameof examples" ON)
option(NAMEOF_OPT_BUILD_TESTS "Build and perform nameof tests" ON)
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2016, 2018 Daniil Goncharov
Copyright (c) 2016, 2018 - 2019 Daniil Goncharov

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
28 changes: 14 additions & 14 deletions README.md
Expand Up @@ -18,7 +18,7 @@ Before, you had to use string literals to refer to definitions, which is brittle

## Features

* C++11
* C++17
* Header-only
* Dependency-free
* Compile-time
Expand All @@ -43,11 +43,10 @@ NAMEOF(person.address.zip_code) -> "zip_code"
NAMEOF(SomeMethod<int, float>) -> "SomeMethod"
NAMEOF_FULL(SomeMethod<int, float>) -> "SomeMethod4<int, float>"
// Name of enum
NAMEOF(SomeEnum::RED) -> "RED"
auto e = SomeEnum::RED;
NAMEOF_ENUM(e) -> "RED"
auto c = Color::RED;
NAMEOF_ENUM(c) -> "RED"
// Name of type
NAMEOF_TYPE(SomeEnum::RED) -> "SomeEnum"
NAMEOF_TYPE(Color::RED) -> "Color"
NAMEOF_TYPE_T(int) -> "int"
// Name of macros
NAMEOF(__LINE__) -> "__LINE__"
Expand All @@ -57,7 +56,7 @@ NAMEOF(__LINE__) -> "__LINE__"
```cpp
constexpr auto cx = NAMEOF(somevar); -> "somevar"
static_assert(cx == "somevar", "Wrong name!");
static_assert("somevar" == cx, "Wrong name!");
```

* Compilation check
Expand Down Expand Up @@ -102,6 +101,8 @@ void f() {

## Remarks

* Nameof return std::string_view.

* The argument expression identifies a code definition, but it is never evaluated.

* If you need raw fully-qualified name, use NAMEOF_RAW().
Expand All @@ -114,24 +115,23 @@ NAMEOF_RAW(&SomeStruct::SomeMethod) -> "&SomeStruct::SomeMethod"
* Instead of macros NAMEOF_ENUM, you can use the function nameof::NameofEnum().
```cpp
nameof::NameofEnum(SomeEnum::RED) -> "RED"
auto e = SomeEnum::RED;
nameof::NameofEnum(e) -> "RED"
nameof::NameofEnum(Color::RED) -> "RED"
auto c = Color::RED;
nameof::NameofEnum(c) -> "RED"
```

* Instead of macros NAMEOF_TYPE, you can use the function nameof::NameofType<>.

```cpp
nameof::NameofType<decltype(SomeEnum::RED)>() -> "SomeEnum"
nameof::NameofType<decltype(Color::RED)>() -> "Color"
nameof::NameofType<int> -> "int"
```

* NAMEOF_ENUM does not work on the GCC.

```cpp
// On GCC.
auto e = SomeEnum::RED;
NAMEOF_ENUM(e) -> "(SomeEnum)0"
auto c = Color::RED;
NAMEOF_ENUM(c) -> "(Color)0"
```
* Spaces and Tabs ignored
Expand All @@ -143,7 +143,7 @@ NAMEOF( somevar ) -> "somevar"

## Integration

You should add required file [nameof.hpp](include/nameof.hpp) and switch to C++11.
You should add required file [nameof.hpp](include/nameof.hpp).

## Compiler compatibility

Expand Down
3 changes: 2 additions & 1 deletion example/CMakeLists.txt
Expand Up @@ -5,12 +5,13 @@ set(OPTIONS "")
if((CMAKE_CXX_COMPILER_ID MATCHES "GNU") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
set(CMAKE_VERBOSE_MAKEFILE ON)
set(OPTIONS -Wall -Wextra -pedantic-errors)
set(OPTIONS ${OPTIONS} -std=c++11)
set(OPTIONS ${OPTIONS} -std=c++17)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
set(OPTIONS /W4)
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.11)
set(OPTIONS ${OPTIONS} /permissive-)
endif()
set(OPTIONS ${OPTIONS} /std:c++17)
endif()

add_executable(example
Expand Down
26 changes: 18 additions & 8 deletions example/example.cpp
@@ -1,7 +1,6 @@
// nameof example
//
// Licensed under the MIT License <http://opensource.org/licenses/MIT>.
// Copyright (c) 2018 Daniil Goncharov <neargye@gmail.com>.
// SPDX-License-Identifier: MIT
// Copyright (c) 2018 - 2019 Daniil Goncharov <neargye@gmail.com>.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -50,14 +49,25 @@ void SomeMethod3() {

template <typename T, typename U>
std::string SomeMethod4(U value) {
return NAMEOF(SomeMethod4<T, U>) + "<" + NAMEOF_TYPE_T(T) + ", " + NAMEOF_TYPE_T(U) + ">(" + NAMEOF_TYPE_T(U) + " " + NAMEOF(value) + ")";
std::string s;
s += NAMEOF(SomeMethod4<T, U>);
s += "<";
s += NAMEOF_TYPE_T(T);
s += ", ";
s += NAMEOF_TYPE_T(U);
s += ">(";
s += NAMEOF_TYPE_T(U);
s += " ";
s += NAMEOF(value);
s += ")";
return s;
}

template <typename T>
class SomeClass {
public:
void SomeMethod5() const {
std::cout << nameof::NameofType<T>() << std::endl;
std::cout << nameof::nameof_type<T>() << std::endl;
}

template <typename C>
Expand All @@ -75,7 +85,7 @@ struct Long {
LL ll;
};

enum class Color { RED, GREEN, BLUE };
enum class Color { RED = -10, GREEN, BLUE };

SomeStruct structvar;
Long othervar;
Expand All @@ -84,14 +94,14 @@ SomeStruct* ptrvar = &structvar;
int main() {
// Compile-time nameof.
constexpr auto constexpr_work_fine = NAMEOF(structvar);
static_assert("structvar" == constexpr_work_fine, "");
static_assert("structvar" == constexpr_work_fine);

// Enum name.
std::cout << NAMEOF(Color::RED) << std::endl; // RED
std::cout << NAMEOF_ENUM(Color::RED) << std::endl; // RED
auto color = Color::RED;
std::cout << NAMEOF(color) << std::endl; // color
std::cout << NAMEOF_ENUM(color) << std::endl; // RED
std::cout << nameof::nameof_enum(color) << std::endl; // RED

// Variable name.
std::cout << NAMEOF(structvar) << std::endl; // structvar
Expand Down

0 comments on commit 80a3e6d

Please sign in to comment.