tasks.jsonについて
tasks.json
{ "version": "2.0.0", "tasks": [ { "type": "cppbuild", "label": "C/C++: g++ アクティブなファイルのビルド", "command": "/usr/bin/g++", "args": [ "-fdiagnostics-color=always", "-g", "${file}", "-o", "${fileDirname}/${fileBasenameNoExtension}" ], "options": { "cwd": "${fileDirname}" }, "problemMatcher": [ "$gcc" ], "group": { "kind": "build", "isDefault": true }, "detail": "コンパイラ: /usr/bin/g++" } ] }
command
実行されるコマンド。外部プログラムでもシェルでも可
options
cwd 実行されるプログラムまたはスクリプトの現在の作業ディレクトリ。省略すると、Code の現在のワークスペースのルートが使用されます。 current working directory??
problemMatcher
problemMatcherプロパティ: エラー発生時にVS Codeに渡されるメッセージのフォーマットをどんな形式のメッセージとして処理するかの指定。この場合は「$tsc」となっているが、これはtscコマンド(TypeScriptコンパイラー)が出力する形式のメッセージとして処理することを指定している
参考
c_cpp_properties.jsonについて
生成されたc_cpp_properties.json
{ "configurations": [ { "name": "Linux", "includePath": [ "${workspaceFolder}/**" ], "defines": [], "compilerPath": "/usr/bin/gcc", "cStandard": "gnu17", "cppStandard": "gnu++14", "intelliSenseMode": "linux-gcc-x64" } ], "version": 4 }
役割
configurations
IntelliSense エンジンにプロジェクトと環境設定に関する情報を提供する設定オブジェクトの配列。デフォルトでは、拡張モジュールはあなたのオペレーティングシステムに基づいた設定を作成します。さらに設定を追加することもできます。
name
コンフィギュレーションを識別するためのフレンドリーな名前です。Linux、Mac、Win32は、それらのプラットフォームで自動選択されるコンフィギュレーション用の特別な識別子です。VS Codeのステータスバーには、どのコンフィギュレーションがアクティブであるかが表示されます。また、ステータスバーのラベルをクリックすると、アクティブなコンフィギュレーションを変更することができます。 (WSL:Ubuntu とかに変更したほうがいいのか...?)
includePath
インクルードパスとは、ソースファイルに含まれるヘッダーファイル(#include "myHeaderFile.h "など)を含むフォルダーのことです。インテリセンス・エンジンがインクルード・ヘッダー・ファイルを検索するときに使用するパスのリストを指定します。これらのパスでの検索は再帰的ではありません。再帰的な検索を行う場合は を指定します。例えば、${workspaceFolder}/ はすべてのサブディレクトリを検索しますが、${workspaceFolder} は検索しません。Visual StudioがインストールされているWindowsの場合、またはcompilerPath設定でコンパイラーが指定されている場合は、このリストにシステムインクルードパスをリストアップする必要はありません。
defines
ファイルを解析するときに IntelliSense エンジンが使用するプリプロセッサー定義のリストです。オプションで、VERSION=1 のような値を設定するために = を使用します。???
intelliSenseMode
MSVC、gcc、または Clang のアーキテクチャ固有の変種に対応する、使用するインテリセンス モードです。設定されていない場合、または ${default} に設定されている場合、拡張機能はそのプラットフォームのデフォルトを選択します。
プラットフォームのデフォルト
Windows: msvc-x64 Linux: gcc-x64 macOS: clang-x64
これはいじらなくてよさそう
参考
c_cpp_properties.jsonについて
生成されたc_cpp_properties.json
{ "configurations": [ { "name": "Linux", "includePath": [ "${workspaceFolder}/**" ], "defines": [], "compilerPath": "/usr/bin/gcc", "cStandard": "gnu17", "cppStandard": "gnu++14", "intelliSenseMode": "linux-gcc-x64" } ], "version": 4 }
C++ lambda
#include <algorithm> #include <functional> #include <iostream> #include<vector> using namespace std; int main(){ int n=5; vector<int>v(n); for(int i=0;i<n;i++){ v[i]=3; } // sort(v.begin(),v.end(),[](int i,int j){ if(i==j){return true;} else{return i>j;}}); for(int i=0;i<n;i++){ cout<<v[i]<<endl; } return 0; }
C++のラムダにおける条件分岐の1例
#include <algorithm> #include <functional> #include <iostream> #include<vector> using namespace std; int main(){ auto b=[](int i,int j){ return [i,j](){ if(i==j){return 0;} else{return i+j;}};}; cout<<b(2,3)()<<endl; return 0; }
lambda
#include <algorithm> #include <functional> #include <iostream> #include<string> #include<vector> #include <algorithm> using namespace std; void construct(vector<int>&v,int k) { auto compare = [](int k) { return [k](int i, int j) { return i+k < j+j; }; }; int n{}; // for (k = 1; k <= n; k *= 2) { sort(v.begin(), v.end(), compare(k)); } } int main(){ vector<int>v(5); for(int i=0;i<5;i++){ v[i]=i; } int k=0; construct(v,k); }