- assert で示されている条件は,正しくプログラムが書けている場合,必ず成立する
- 状況次第で失敗する可能性のある条件を assert にかけてはならない
- 例として,ユーザ入力や設定ファイルの妥当性検証を assert で行なってはならない
- 例外にするべきか assert にするべきか迷った場合には,とりあえず例外を使うことを検討する
- どの例外を投げるのが相応しいかを考える過程で,思考が整理されることが期待できる
- 思考整理ができなかった場合には,その旨をソースコードや pull req. のコメントに残す
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <utility> | |
namespace etude { | |
namespace bracket_impl_ { | |
namespace here = bracket_impl_; | |
template<class T> | |
T& as_lvalue(T&& x) { | |
return x; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template<class T, class D> | |
auto make_unique_ptr(T* p, D d) noexcept | |
-> std::unique_ptr<T, D> { | |
return std::unique_ptr<T, D>(p, std::move(d)); | |
} | |
auto get_two_resources() | |
-> std::pair<std::shared_ptr<Res1>, std::shared_ptr<Res2>> { | |
Res1* res1_ = {}; | |
Res2* res2_ = {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string> | |
#include <cstring> | |
#include <cerrno> | |
#include <cstdio> | |
#include <cstdlib> | |
#include <stdexcept> | |
#include <boost/optional.hpp> | |
boost::optional<std::string> get_line(std::FILE* fp) { | |
std::string s; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <boost/utility/string_ref.hpp> | |
#include <utility> | |
#include <iostream> | |
std::size_t all_length(std::initializer_list<boost::string_ref> ss) { | |
std::size_t n = 0; | |
for (auto const& s : ss) { | |
n += s.size(); | |
} | |
return n; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <type_traits> | |
#include <utility> | |
namespace etude { | |
namespace copy_impl_ { | |
struct base_ {}; | |
struct derived_ : base_ {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef INCLUDED_ASSERT_HPP_ | |
#define INCLUDED_ASSERT_HPP_ | |
#ifndef ETUDE_DISABLE_ASSERTIONS | |
#include <glog/logging.h> | |
// declares expr to be true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Tape( | |
Tape(), initTape, moveRight, moveLeft, | |
readHead, writeHead, modifyHead) where | |
import Data.List (intercalate) | |
data InfList a = InfList a (InfList a) | Repeat a | |
splitHead :: InfList a -> (a, InfList a) | |
splitHead (InfList a as) = (a, as) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdexcept> | |
#include <utility> | |
#include <cassert> | |
#if 0 | |
#define NORETURN [[noreturn]] | |
#else | |
#define NORETURN | |
#endif |