Giter VIP home page Giter VIP logo

cpp-book's Introduction

C++11の文法と機能
C++11/14コア言語
GitHub: https://github.com/EzoeRyou/cpp-book
GitHub Pages: http://ezoeryou.github.io/cpp-book/C++11-Syntax-and-Feature.xhtml

本書は紙の本と達人出版の電子書籍で購入できる。
購入すると、筆者が自由な参考書の執筆に使える時間が増える。


筆者について

名前:江添亮
Mail : [email protected]
Blog : http://cpplover.blogspot.jp/


序

本書はC++11のコア言語の文法と機能を、標準規格書に従って解説したものである。正式なC++規格書として発行された後の、ひとつ後のドラフト規格、N3337 を参考にしている。ドラフト規格を参考にした理由は、正式なC++規格書は、個人での入手が煩わしいためである。読者に入手が困難な資料を元に記述された参考書は価値がない。そのため、読者が容易に入手できるドラフト規格のうち、正式なC++規格書とほとんどかわらないN3337を参考にした。

本書の対象読者は、C++を記述するものである。C++実装者ではない。そのため、サンプルコードを増やし、冗長な解説を増やし、C++コンパイラーを実装するための詳細な定義は省いた。そもそも本書はC++規格の翻訳ではなく、C++規格の検証に使うことはできない。

本書の執筆は、まだC++11がC++0xと呼ばれていた2010年から始まっている。そのため、当時のドラフト規格を参考に書かれた部分もあり、正式なC++11規格とは異なっている可能性がある。また、正式に発行されたC++11規格には不具合も多数見つかっているため、C++14では異なっている部分もある。また、ドラフトの時点であまりにも変更が激しい箇所は飛ばしたので、漏れもある。

cpp-book's People

Contributors

chatsftd avatar ezoeryou avatar gyuque avatar hiroshi-manabe avatar inouati avatar k-takata avatar kakkoko avatar kariya-mitsuru avatar makotokato avatar mrdagon avatar pfpacket avatar picohz avatar rhysd avatar syohex avatar tan90909090 avatar tzik avatar watiko avatar y0z avatar yohe avatar yutopp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cpp-book's Issues

lvalueとrvalue: 書きかけと思われる箇所

lvalueとrvalue(Lvalues and rvalues) に、文章が途中で切れているパラグラフがあります。

<p>
ただし、C++では、constなlvalueリファレンスで、rvalueを束縛できるという
</p>

<pre>
int f() { return 0 ; }

int main()
{
    int const &amp; lvalue_ref = f() ; // OK
}
</pre>

{ } の記入漏れ4ヶ所

{ } の記入漏れ4ヶ所。

12.6.1 明示的な初期化(Explicit initialization)

【24990 行】

 struct X
 {
-    X( int ) ;
+    X( int ) { }
-    X( int, int ) ;
+    X( int, int ) { }
-    X( int, int, int ) ;
+    X( int, int, int ) { }
 } ;

 int main()
 {
    X x1( 1 ) ; // X::X(int)
    X x2( 1, 2 ) ; // X::X(int,int)
    X x3( 1, 2, 3 ) ; // X::X(int,int,int)
 }

詳しくは、初期化子の直接初期化を参照。

また、=(イコール)記号に続いて値を指定することで、初期化することもできる。

 struct X
 {
-    X( int ) ;
+    X( int ) { }
 } ;

 int main()
 {
    X x = 0 ; // X::X(int)
 }

誤植の報告

----------
8.3.5 関数(Functions)

template < typename T1, typename T2 >
??? multiply( T1 t1, T2 t2 )
{
    return t1 * t2 ;                      (←参考)
}
----------
ここで、???という部分で、戻り値の型を指定したい。ところが、T1とT2に対して
operator +を適用した結果の型は、テンプレートをインスタンス化するまで分からない。 ←誤:'+'、正:'*'

誤植の報告2

8.3.5 関数(Functions)の最後

// OK、ポインター
auto f() -> void (*)(void);
auto f() -> int (*)[5]               ←int(&)[5];
// OK、リファレンス
auto f() -> void (&)(void);
auto f() -> int (&)[5]              ←int(&)[5];

誤植の報告:←もしかしてptr_func()?

8.3.1 ポインター(Pointers)
void func( void ) { } // 型はvoid (void)

void g()
{
    void (*ptr_func)( void ) = &func ;
    ref_func() ; // 関数呼び出し             ←もしかしてptr_func()?

    int array[5] ; // 型はint [5]
    int (*ptr_array)[5] = &array ;
}

誤植の報告:

よく分からずに初めてプシュしましたらエラーで送れませんでした。自分の試験ページには送れた様なのですが。
(間違えて「Closed」ボタンを押しました。)ごめんなさい。切り貼りします。
セミコロンと引数の追加です。

@@ -5849,7 +5849,7 @@ int main()
[] {
int x = 0 ;
++x ;

  •    }
    
  •    };
    

    f() ;

    auto g = []
    @@ -6381,10 +6381,10 @@ h = f ;

    void (*ptr1)(void) = []{} ;
    -auto (*ptr2)(int, int, int) -> int = [](int a, int b, int c) -> int { return a + b + c ; }
    +auto (*ptr2)(int, int, int) -> int = [](int a, int b, int c) -> int { return a + b + c ; };
    
    // 蜻シ縺ウ蜃コ縺吶�
    -ptr1() ; ptr2() ;
    +ptr1() ; ptr2(1, 2, 3) ;
    

文末の句点

末尾に句点(。)がない文を探している時に疑問に思ったこと。

基本的にp要素内の文章末尾には句点をつけているのに対して、

<ul>
<li>
<p>
文1。文2
</p>

<p>
文3
</p>
...

</li>
</ul>

このようにリストの一部になっている場合、末尾にはつけていなかったので全体を通してそうなのだろうと思っていたところ、後半になるにつれ徐々に、ついていたりいなかったり…

また、リスト内でない時も末尾が場合(漢字で終わるときか?)で終わるとき統一されていないようです。

どちらが好ましいのか指針を示していただきたく。

sizeofでの()について

構文としては、sizeof 式sizeof (形名)は区別され、前者は括弧が必須ではありません。

N3337 p104 "5.3 Unary expresssions"では

sizeof unary-expression
sizeof ( type-id )
sizeof ... ( identifier )

コメント追加 8.5.3 (このissuesは間違っているかもしれない)

【グローバル空間ではエラーになる new int()】

8.5.3 値初期化(value-initialize)

空の()を書く事ができる初期化子には、5.5.3 関数形式のキャスト、5.6.4 new、12.6.2 メンバー初期化がある。

  // 関数形式のキャスト
 int x = int() ;
 // new
【18122行】
- new int() ;
+ new int() ; // グローバル空間ではエラーになる ←

 // メンバー初期化
 class C
 {
    int member ;
    C() : member()
    { }
 } ;

const 変数を初期化する。 = 0;

8.5.6 リファレンス(References)

 struct Base { } ;
 struct Derived : Base { } ;

 int main()
 {
    int object ;
    int & r1 = object ;

    Base base ;
    Base & r2 = base ;
 // 派生クラスのlvalueでも初期化できる
    Derived derived ;
    Base & r3 = derived ;

【18784行】
-   int const const_object ;
+   int const const_object = 0 ;
    // OK
    int const & r5 = const_object ;
    int const volatile & r6 = const_object;
 }

誤植の報告

正:int
誤:void

9.8.2 staticデータメンバー(Static data members)

 struct S
 {
    static int member ;
 } ;

 // クラス名 :: メンバー名
【24273行】
-void S::member = 0 ;
+int S::member = 0 ;

誤植の報告(8.5.3)

8.5.3 値初期化(value-initialize)
初期化の文法と方法

 struct S
 {
【17951行】
-    S() : x(1) { }            ←ゼロ初期化
+    S() : x(0) { }
    int x ;
 } ;

 S s ; // staticストレージの期間を持つオブジェクト

ここでは、Sのデフォルトコンストラクターが実行される前に、データメンバーのxはゼロ初期化されている。

【解説該当箇所:xはゼロ初期化】

変数名の重複: m2 と m3

【変数名の重複: m2 と m3】

8.5.4 アグリゲート(Aggregates)

 struct SubAggregate { } ;

 struct Aggregate
 {
    int m1 ;
    SubAggregate s1 ;
    int m2 ;
【18542行】
-    SubAggregate m2 ;
+    SubAggregate s2 ;
    int m3 ;
-    SubAggregate m3 ;
+    SubAggregate s3 ;
 } ;

 SubAggregate s ;

 Aggregate a =
 {
    1,
    { },// 空の初期化リスト
    2,
    s,// オブジェクトの変数
    3,
    SubAggregate() // 関数形式のキャスト
 } ;

数詞の使い方

1つ1つ一つなど(左から半角、全角、漢数字)
いずれも使われているので統一したほうが好いのではないかという提案。

あるいは一つでなければならない1つ目のように使い分けるなど。

関数の宣言方法の記載ミス

8.3.5 関数(Functions)において、

識別子 ( 仮引数リスト ) CV修飾子opt リファレンス修飾子opt 例外指定opt

と記載されていますが、正しくは下記ではないでしょうか?

指定子 識別子 ( 仮引数リスト ) CV修飾子opt リファレンス修飾子opt 例外指定opt

n3337では、In a declaration T D where D has the formと前置きして、Dについて記載されてます。
そのDの部分だけを記載されているようです。


古いものへコメントしてすいません。

実装依存の文字を使った識別子

半ば質問ですが。

2.6 識別子(Identifiers)
で実装依存の文字として
int 変数;
とサンプルコードにありますが、プリプロセスでUCNに変換されるため"変数"と言う文字が識別子に使えるかはソースコードのエンコーディングにUTF-8等を認めているかどうかの問題のはずです。
規格書を読むと実装依存の文字とは$や@等を指しているとも解釈出来ます。
大体のC++コンパイラでは$が識別子に使えるようですし。
int $variable$;
とするのが正しいのではないかと思うのですがどうなんでしょうか?

cpp-bookについての要望

・ページ番号が欲しい。
・・理由1:ブラウザの幅を変えると、読んでいる位置が変わって分からなくなる。(巨大な1ページ物だから)
・・理由2:ページ番号を控えておいて後日続きを読むため。その他。
  (出来れば「しおり」機能が有ればよいのだけど)

5.20 代入と複合代入演算子 複合代入演算子の説明

複合代入演算子の説明に「opには、任意の複合代入演算子が入る。」とあるのですが、「op=」が複合代入演算子なのでちょっと説明がおかしい気がします。
「op」を示す言葉が思い浮かばないのですが…

8.2 曖昧解決(Ambiguity resolution)

8.2 曖昧解決(Ambiguity resolution)

S y( static_cast(d) ); // S型の変数yの宣言   ←  かな?
S z = int(d); // S型の変数zの宣言
}

---------<別件で私の意見>--------
2.7 キーワード(Keywords) 項目で、
キーワードをアルファベット順に並べてほしい。(実は並べてあるが)
一見ランダムに並べてあるようにみえる。(TAB位置に揃えるとか、表にするとか)
初心者の目次は、キーワードからだと思う。
できればキーワードの説明位置にリンクして欲しい。
私のC言語辞典は手垢がいっぱい付いている。
(欲を言うと、本の最後に用語の索引が有るといいな)

decltype解説で、c.value はpublicか?

【14496行】
class C {
public: //←必要か?
int value ;
} ;
C c ;
// decltype(c)の型は、class C
decltype(c) t2 ;
// decltype(c.value)の型は、int
decltype(c.value) t3 ; //←エラーが出る

publicの説明ではないのでどうでもよいのかもしれない。間違えたことだったらごめんなさい。
初投稿です。不備が有ったらごめんなさい。

static が不要か

static が不要か

8.5.4 アグリゲート(Aggregates)

 struct S
 {
    int x ;
    static int static_data_member ; // staticデータメンバー
    int y ;
    int : 8 ; // 無名ビットフィールド
    int z ;
 } ;
【18460行】
- static int S::static_data_member ;
+        int S::static_data_member ;

 S s = { 1, 2, 3 } ;
 // s.x = 1, s.y = 2, s.z = 3

この例では、static_data_memberと、yとzとの間にある無名ビットフィールドは、リスト初期化の際には、メンバーとして考慮されない。

コードの例示を示すコロンの有無

<p>
アクセス指定子によりクラスのデフォルトコンストラクターからは利用できない場合の例
</p>
<p>
コンストラクターに関数tryブロックを使う例:
</p>

これに関しても基準があると好いです。

エラーにならない ?

コードを打ち込んだらエラーにならない所がある。
3ヶ所。
難しくなって、内容をまだ理解していない。

10.3 virtual関数(Virtual functions)

struct Base { } ; // 基本クラス
struct Derived : Base { } ; // 派生クラス
struct Other { } ; // BaseやDerivedとは派生関係にないクラス

// クラスが同じ
struct B { virtual Base & f() ; } ;
struct D : B { virtual Base & f() ; } ;

// B::fのクラスはD::fのクラスの基本クラス
struct B1 { virtual Base & f() ; } ;
struct D1 : B { virtual Derived & f() ; } ;

// エラー
【21972行】 エラーにならない
struct B2 { virtual Derived & f() ; } ;       ←正常
struct D2 : B { virtual Base & f() ; } ;      ←正常

// エラー
struct B3 { virtual Base & f() ; } ;           ←正常
struct D3 : B { virtual Other & f() ; } ;     ←これのみエラーに成る?

ラムダ式の戻り値型の推測について

「ラムダ式の基本的な使い方」で記載されている以下のサンプルについて。
エラーで記載されている例は OK ではないでしょうか。
"return x ;"は lvalue から rvalue への型変換が適用されて戻り値の型はint?
試してみたらコンパイルは通るようです。

// エラー、戻り値の型はvoidだが、値を返している
[]
{
    int x = 0 ;
    return x ;
}() ;


// OK、戻り値の型を、明示的に指定している。
[] -> int
{
    int x = 0 ;
    return x ;
}() ;

誤変換2ヶ所

誤変換2ヶ所。(”関節”で検索)
正:間接
誤:関節
【21268行】と【21288行】

Visual Studio12 のみの動作なのか? (ここに書いても良いか迷ったが)

----------
8.3.2 リファレンス(References)

void f( int obj )
{
    int const & a = obj ; // OK、int constへのリファレンス

    //■ Visual Studio12 で「warning C4227: 旧形式が使用されています : 参照の修飾子は無視されます。」 警告となる。
    int & const b = obj ; // エラー、リファレンスへのCV修飾はできない
}
----------
----------
8.3.2 リファレンス(References)
void f()
{
    int * ptr = nullptr ;

    //■ Visual Studio12 ではエラーにならない。
    int & ref = *ptr ; // エラー、nullポインターを参照している
}
----------

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.