Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Class member type pakai PascalCase #2

Open
janucaria opened this issue Aug 15, 2019 · 0 comments
Open

Class member type pakai PascalCase #2

janucaria opened this issue Aug 15, 2019 · 0 comments
Labels
enhancement New feature or request

Comments

@janucaria
Copy link
Contributor

Waktu diskusi tentang style nama class member type, style yang mau dipakai sebenarnya PascalCase seperti contoh berikut.

struct Foo {
    using BarBaz = int;
};

tapi karena API dari standard library seperti iterator yang harus pakai snake_case, jadi stylenya akhirnya diganti menjadi snake_case biar konsisten.

struct ContainerIterator {
    // member type harus snake_case kalau mau pakai std::distance
    using difference_type = ptrdiff_t;
    using value_type = int;
    using pointer = int*;
    using reference = int;
    using iterator_category = std::forward_iterator_tag;

    // snake_case
    using foo_bar = int;

    // ...
};

code lengkapnya di https://godbolt.org/z/Z-FNIY

tapi, ternyata masalah API iterator ini bisa diganti dengan type traits seperti iterator_traits, jadi tidak ada lagi situasi yang harus pakai snake_case, sehingga nama class member type bisa PascalCase saja supaya nama type konsisten semua.

struct ContainerIterator {
    // PascalCase
    using FooBar = int;
    
    // ...
};

namespace std {
    // template specialization untuk ContainerIterator
    template<>
    struct iterator_traits<ContainerIterator> {
        using difference_type = ptrdiff_t;
        using value_type = int;
        using pointer = int*;
        using reference = int;
        using iterator_category = std::forward_iterator_tag;
    };
}

https://godbolt.org/z/WkH3dt

@janucaria janucaria added the enhancement New feature or request label Aug 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant