0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
#include <iostream>
#include <type_traits>
#include <mutex>
#include <string>
#include <memory>
#include <vector>
#include <chrono>
void bad_function(void* data) {
/// НИКОГДА ТАК НЕ ПИШИ
if (data) {
std::cout << *(std::string*)data << "\n";
}
}
template<typename T = std::string,
typename Alloc = std::allocator<T>,
typename = std::enable_if_t<std::is_constructible_v<T, const char*>>,
typename Clock = std::chrono::high_resolution_clock,
typename TimePoint = typename Clock::time_point>
class GoodFunctionImpl {
private:
static std::recursive_mutex mtx_;
Alloc alloc_;
std::vector<T, Alloc> buffer_;
std::string context_;
TimePoint init_time_;
template<typename U>
using is_valid_type = std::conjunction<
std::is_same<std::decay_t<U>, T>,
std::is_constructible<T, U>
>;
void internal_log(const std::string& msg) {
buffer_.push_back(T(msg.c_str()));
}
public:
GoodFunctionImpl() : init_time_(Clock::now()) {
internal_log("GoodFunctionImpl initialized");
}
template<typename U,
typename = std::enable_if_t<is_valid_type<U>::value>>
decltype(auto) execute(U&& input) {
std::lock_guard<std::recursive_mutex> lock(mtx_);
internal_log("Processing started");
T processed = std::forward<U>(input);
auto duration = Clock::now() - init_time_;
auto duration_ms = std::chrono::duration_cast<
std::chrono::milliseconds>(duration).count();
std::cout << processed << " (runtime: "
<< duration_ms << "ms)\n";
internal_log("Processing completed");
return processed;
}
size_t get_buffer_size() const { return buffer_.size(); }
};
template<typename T, typename Alloc, typename, typename Clock, typename TimePoint>
std::recursive_mutex GoodFunctionImpl<T, Alloc, Clock, TimePoint>::mtx_;
void good_function(const std::string& input) {
// Пиши ВОТ ТАК
// так делают все
// это стабильно и надежно
// так надо
GoodFunctionImpl<> impl;
auto result = impl.execute(input);
std::cout << "Buffer entries: "
<< impl.get_buffer_size() << "\n";
}
lisp-worst-code ,
06.12.2025 (Updated 06.12.2025 )
0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
void makeShape(ShapeArguments shape)
{
if (shape.type == ShapeType::Square)
{
throw Square(shape);
}
if (shape.type == ShapeType::Cicle)
{
throw Circle(shape);
}
}
void handleShape(ShapeArguments shape)
{
try
{
makeShape(shape);
}
catch (const Square& square)
{
// Work with square
}
catch (const Circle& circle)
{
// Work with circle
}
}
factory
kcalbCube ,
25.11.2025 (Updated 25.11.2025 )
0
1 2 3 4 5 6 7 8 9
SparseMatrix<double> mat(rows,cols);
for (int k=0; k<mat.outerSize(); ++k)
for (SparseMatrix<double>::InnerIterator it(mat,k); it; ++it)
{
it.value();
it.row(); // row index
it.col(); // col index (here it is equal to k)
it.index(); // inner index, here it is equal to it.row()
}
Random access to the elements of a sparse object can be done through the coeffRef(i,j) function. However, this function involves a quite expensive binary search. In most cases, one only wants to iterate over the non-zeros elements. This is achieved by a standard loop over the outer dimension, and then by iterating over the non-zeros of the current inner vector via an InnerIterator. Thus, the non-zero entries have to be visited in the same order than the storage order.
CHayT ,
03.09.2025 (Updated 03.09.2025 )
0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
// https://github.com/ggml-org/llama.cpp/blob/f4c3dd5daa3a79f713813cf1aabdc5886071061d/examples/simple/simple.cpp#L23
// parse command line arguments
{
int i = 1;
for (; i < argc; i++) {
if (strcmp(argv[i], "-m") == 0) {
if (i + 1 < argc) {
model_path = argv[++i];
} else {
print_usage(argc, argv);
return 1;
}
} else if (strcmp(argv[i], "-n") == 0) {
if (i + 1 < argc) {
try {
n_predict = std::stoi(argv[++i]);
} catch (...) {
print_usage(argc, argv);
return 1;
}
} else {
print_usage(argc, argv);
return 1;
}
} else if (strcmp(argv[i], "-ngl") == 0) {
if (i + 1 < argc) {
try {
ngl = std::stoi(argv[++i]);
} catch (...) {
print_usage(argc, argv);
return 1;
}
} else {
print_usage(argc, argv);
return 1;
}
} else {
// prompt starts here
break;
}
}
if (model_path.empty()) {
print_usage(argc, argv);
return 1;
}
if (i < argc) {
prompt = argv[i++];
for (; i < argc; i++) {
prompt += " ";
prompt += argv[i];
}
}
}
Парсинг аргументов командной строки
j123123 ,
16.03.2025 (Updated 16.03.2025 )
0
1
Мда... Какое же всё таки говнецо это Ваше США.
3uMuCTOH ,
04.03.2025 (Updated 04.03.2025 )
0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include <iostream>
union is_odd {
long long int number;
bool yes : sizeof(long long int);
};
int main() {
std::boolalpha(std::cout);
for (long long int i = -10; i < 10; ++i) {
std::cout << i << " is odd? "
<< is_odd{ .number = i }.yes
<< "\n";
}
}
DEMO:
https://godbolt.org/z/5exc84eYK
shittycode43 ,
15.11.2024 (Updated 15.11.2024 )
0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
xxx: Теперь сделайте так, чтобы цифры выводились следующим образом (используя программу из предыдущего задания):
1
2 1
3 2 1
4 3 2 1
5 4 3 2 1
yyy:
#include <print>
inline constexpr std::size_t kSize = 5;
template <std::size_t N, std::size_t NN>
constexpr auto operator+(const std::array<char, N>& first, const std::array<char, NN>& second) -> std::array<char, N + NN> {
std::array<char, N + NN> response; // NOLINT
std::ranges::copy(first, response.begin());
std::ranges::copy(second, response.begin() + first.size());
return response;
};
auto main() -> int {
[]<std::size_t... Is>(std::index_sequence<Is...>) {
// clang-format off
([&]<std::size_t... IIs, std::size_t... IIIs>(std::index_sequence<IIs...>, std::index_sequence<IIIs...>) {
constexpr std::format_string<decltype(IIs)...> fmt = [] {
static constexpr auto response = ((std::ignore = IIIs, std::array{' ', ' '}) + ... + ((std::ignore = IIs, std::array{'{', '}', ' '}) + ... + std::array{'\0'}));
return response.begin();
}();
constexpr auto v = Is;
std::println(fmt, (v - IIs + 1)...);
}(std::make_index_sequence<Is + 1>(), std::make_index_sequence<kSize - Is - 1>()), ...);
// clang-format on
}(std::make_index_sequence<kSize>());
};
Fluttie ,
06.11.2024 (Updated 06.11.2024 )
0
1
Админ - уебок, хранивший пароли открытым текстом
Чекайте свои мыла в утечках, ебланы
aleksusklim ,
26.10.2024 (Updated 26.10.2024 )
0
Удалите мой аккаунт
aleksusklim ,
25.10.2024 (Updated 25.10.2024 )
0
Удалите мой аккаунт
aleksusklim ,
25.10.2024 (Updated 25.10.2024 )