接頭辞やハンガリアン記法は採用しない。
class CHoge {
};
class Hoge {
private:
int m_value;
};
Hoge g_hoge;
class Hoge {
private:
int value_;
};
bool fCondition; char *pSomething;
char *dataptr; std::shared_ptr<Hoge> hoge_ptr;
char *lpszText;
switch (n) {
case 1: return "a"; // comment
case 12: return "ab"; // comment
case 123: return "abc"; // comment
}
if (cond1) {
// do something
} else if (cond2) {
// do something
} else {
// do something
}
if (c != 'a' && c != 'b' && c != 'c') {
// do something
}
if (c == 'a' || c == 'b' || c == 'c') {
// nop
} else {
// do something
}
while (cond) {
// do something
}
do {
// do something
} while (cond);
for (int i = 0; i < 10; i++) {
// do something
}
switchとcaseのインデントは同じ深さとする。
switch (n) {
case 1:
// do something
break;
}
switch (n) {
case 1:
// do something
break;
}
switch (n) {
case 1:
// do something
break;
case 2: // fallthru
case 3:
// do something
break;
}
hoge();
hoge() ;
int n = (12 + 34);
int n = ( 12+34 );
bool g = !f;
bool g = ! f;
hoge(a, b, c);
while ((c = get()) != 0) {
}
if (Hoge *hogeptr = dynamic_cast<Hoge *>(baseptr)) {
}
char *p;
char* p;
if (!CreateProcessW(0, &tmp[0], 0, 0, TRUE, CREATE_NO_WINDOW, 0, 0, &si, &pi)) {
}
if (!CreateProcessW(0, &tmp[0], 0, 0, TRUE,
CREATE_NO_WINDOW, 0, 0, &si, &pi)) {
}
bool f;
if (f) {
}
if (!f) {
}
bool f;
if (f == true) {
}
if (f == false) {
}
bool f;
if (true == f) {
}
if (false == f) {
}
char *p;
if (p) {
}
if (!p) {
}
char *p;
if (p != nullptr) {
}
if (p == nullptr) {
}
char *p;
if (nullptr != p) {
}
if (nullptr == p) {
}
int n;
if (n == 42) {
}
int n;
if (42 == n) {
}
if (c >= '0' && c <= '9') {
}
if ('0' <= c && c <= '9') {
}
void hoge(int arg1, int arg2, int arg3)
{
}
void hoge(int arg1,
int arg2,
int arg3)
{
}
void
hoge(int arg1, int arg2, int arg3) {
}
struct HogeArgs {
int arg1;
int arg2;
int arg3;
};
void hoge(HogeArgs *args)
{
}
void func(int *v)
{
*v = 123;
}
void func(int &v)
{
v = 123;
}
void func(Hoge *hoge)
{
}
void func(Hoge &hoge)
{
}
void func(Hoge const *hoge)
{
}
void func(Hoge const &hoge)
{
}
class Hoge {
int getValue() const
{
return value;
}
};
std::vector<Hoge> hogevec;
for (Hoge &hoge : hogevec) {
// do something
}
namespace ns1 {
namespace ns2 {
class Hoge {
};
}} // namespace ns1::ns2
クラスが大きくなってきたら、pimplイディオムの採用を検討する。ポインタは m を推奨。
class Hoge {
private:
struct Private;
Private *m;
public:
Hoge();
~Hoge();
];
struct Hoge::Private {
};
Hoge::Hoge()
: m(new Private)
{
}
Hoge::~Hoge()
{
delete m;
}
クラスメンバ関数内で、pimplイディオム以外の用途で m という変数を使用することを避ける。