if (it != nullptr && *it != nullptr && **it != nullptr && ***it != nullptr) {
(**it)(this);
}🤣11
template <class T, class E>
struct Result : public Either<T, E> {
template <class V>
Result(V&& v) : Either<T, E>(std::forward<V>(v)) {
}
template <class V>
Result(const V& v) : Either<T, E>(v) {
}
auto Ok() const noexcept -> bool {
return this->template Is<T>();
}
auto Unwrap() -> T& {
try {
return this->template As<T>();
} catch (...) {
throw this->template As<E>();
}
}
auto Err() -> E {
return this->template As<E>();
}
auto operator!() -> T& {
return Unwrap();
}
};
auto Res() -> monad::Result<monad::Unit, err::RuntimeError> {
return err::RuntimeError("LOL");
}
auto Throws() -> void {
!Res();
}
🔥4
#include <string>
#include <fmt/format.h>
template<typename F>
struct Scope_exit {
F f;
Scope_exit(F f): f(std::move(f)) {}
~Scope_exit() { f(); }
};
auto make_string() {
std::string result;
Scope_exit guard = [&] {
fmt::println("About to return '{}'", result);
};
for (int i = 0; i < 20; i++) {
result += std::to_string(i);
}
return result;
}
int main() {
auto s = make_string();
}
$ # Either behavior is legal of a C++ compiler
$ g++ a.cpp -lfmt -o a && ./a
About to return '012345678910111213141516171819'
$ g++ a.cpp -lfmt -o a -fno-elide-constructors && ./a
About to return ''
🥴3👍2
auto(*foo)(size_t)->void* {
malloc //
};🥰6
Постироничные идеи для ебаного C++
&*iovecs_.begin()
using T = std::iter_value_t<decltype(iovecs_.begin())>;
if constexpr(std::is_same_v<std::vector<T>, decltype(iovecs_)>) {
auto* ptr =reinterpret_cast<T*>(iovecs_.begin());
}
Постироничные идеи для ебаного C++
Photo
#постироник_поясняет
https://youtu.be/_fu0gx-xseY?si=AHHplmoJ-xa4jKP6
Автор Гор Нишанов.
Horus латинская версия имени египетского бога Гора
https://youtu.be/_fu0gx-xseY?si=AHHplmoJ-xa4jKP6
Автор Гор Нишанов.
Horus латинская версия имени египетского бога Гора
YouTube
CppCon 2015: Gor Nishanov “C++ Coroutines - a negative overhead abstraction"
http://www.Cppcon.org
—
Presentation Slides, PDFs, Source Code and other presenter materials are available at: https://github.com/cppcon/cppcon2015
—
C++ coroutines are one of the few major features that may land in C++17. We will look at the current standardization…
—
Presentation Slides, PDFs, Source Code and other presenter materials are available at: https://github.com/cppcon/cppcon2015
—
C++ coroutines are one of the few major features that may land in C++17. We will look at the current standardization…
В C ключевое слово
В Фортране буква
fortran означает совместимую с Фортраном линковку.В Фортране буква
C в начале строки означает комментарий.😁9👍4
Известно, что
Также известно, что
Но как можно копировать владеемую строку с nothrow-гарантией?
Публичного такого класса в STL нет. (Раньше в libstdc++ была такая
std::runtime_error владеет строкой, которую копирует в себя при создании и вид на которую возвращает метод what().Также известно, что
std::runtime_error копируемый, причём конструктор копии и оператор присваивания копии у него noexcept, как и остальные методы. Если бы это было не так, std::runtime_error как часть механизма исключений был бы намного менее полезным.Но как можно копировать владеемую строку с nothrow-гарантией?
std::basic_string так не умеет. Реализации std::runtime_error вынуждены реализовать и хранить строку с подсчётом ссылок.Публичного такого класса в STL нет. (Раньше в libstdc++ была такая
std::string, но C++11 запретил такую реализацию.) Поэтому если вам для прикладных целей нужна иммутабельная строка с подсчётом ссылок, то:struct Refcount_str: private std::runtime_error {
using std::runtime_error::runtime_error;
using std::runtime_error::operator=;
~Refcount_str() override = default;
const char* c_str() const noexcept {
return what();
}
char operator[] (std::ptrdiff_t i) const noexcept {
return what()[i];
}
};🤣18