Giriş
Şu satırı dahil ederiz
#include <cctype>#include <cctype>#include <cctype>// API function
void api(void* p) {
// ...
}
// Special case for nullptr
inline void api(std::nullptr_t) {
api((void*)nullptr);
}
// Everything else is disabled
template <class ...T>
void api(T&&... t) = delete;
int main() {
int i = 0;
void* p = &i;
api(p); // Compiles
// api(&i); // Doesn't compile
}template <std::ranges::range R>
auto to_vector(R&& r) {
auto r_common = r | std::views::common;
return std::vector(r_common.begin(), r_common.end());
}#include <cmath>
#include <numeric>
#include <ranges>
#include <utility>
template<typename Container>
auto mean_and_stddev(const Container& values)
{
auto len = static_cast<double>(values.size());
auto mean = std::accumulate(values.begin(), values.end(), 0.0) / len;
auto sdv = // squared differences view
values
| std::views::transform([mean](auto d){ auto x = d - mean; return x*x; })
| std::views::common;
auto stddev = std::sqrt(std::accumulate(sdv.begin(), sdv.end(), 0.0) / len);
return std::pair{ mean, stddev };
}Header files are conventionally suffixed by .h and files containing function or data definitions by .c. ... Other conventions, such as .C, .cxx, .cpp, and .cc, are also found. The manual for your compiler will be quite specific about this issue.
Name mangling is the encoding of function and variable names into unique names so that linkers can separate common names in the language.
If you have ever looked at an objdump of a C++ program, you have likely seen something like this:_ZN3foo3bar3bazI6sampleEE3quxvi3fo
This is a C++ mangled symbol, which encodes the namespaces, classes, and function/template arguments, using the Itanium ABI.Specifically, it is for the following function:void foo::bar::baz<sample>::qux(int, foo);
- All mangled symbols start with _Z.- Everything is case sensitive.- All identifiers are encoded as <length><name>, where <length> is the positive length of <name> in base 10, so foo is encoded as 3foo, sample is encoded as 6sample, etc.
#include <chrono>
bool IsTodayChristmas() {
using namespace std::chrono;
constexpr month_day Christmas = {December / 25};
auto Now = year_month_day{floor<days>(system_clock::now())};
// either
return Now == Christmas / Now.year();
// or
return Now.month() / Now.day() == Christmas;
}
Yerel zamana göre çalışmak istersek şöyle yaparızbool IsTodayChristmas() {
using namespace std::chrono;
constexpr month_day Christmas = {December / 25};
auto Now_local = current_zone()->to_local(system_clock::now());
auto Today = year_month_day{floor<days>(Now_local)};
return Today == Christmas / Today.year();
}