跳转至内容
  • xllmapi - 大模型共享网络 - 内测邀请

    已固定 xllmapi
    18
    0 赞同
    18 帖子
    193 浏览
    johanvxJ

    johanpoisson#outlook.com

  • xllmapi 网页控制台 目前存在的问题

    已锁定 已解决 xllmapi
    2
    0 赞同
    2 帖子
    35 浏览
    SPeakS
    1.给页面加了缓存, 来优化加载问题 2.横幅重叠 - 已经优化 3.token为0应该是缓存问题
  • 开源协议总结

    Open source | 开源
    8
    1 赞同
    8 帖子
    536 浏览
    MoYingJiM

    补一个 0BSD,这个许可证很多时候也被放在与 Unlicense 和 WTFPL 相提并论的(都是公共领域)

  • 1 赞同
    1 帖子
    13 浏览
    尚无回复
  • 请教如何自定义异常

    未解决 现代C++ | mcpp论坛
    5
    0 赞同
    5 帖子
    66 浏览
    SPeakS
    class myException : public std::exception { private: std::string _msg; public: myException(const char* message) noexcept : _msg(message) {} const char* what() const noexcept override { return _msg.c_str(); } };
  • 在CLion 2026.1 中配置API后连接出错

    已锁定 已解决 xllmapi
    3
    0 赞同
    3 帖子
    36 浏览
    FrozenLemonTeeF

    image.png
    现在ok了

  • 0 赞同
    1 帖子
    44 浏览
    尚无回复
  • 0 赞同
    5 帖子
    116 浏览
    Mudrock-JOM

    好像还是不行?
    屏幕截图 2026-03-06 094952.png

  • 0 赞同
    7 帖子
    143 浏览
    SPeakS

    @sleepyiang 找到原因, 这个时项目里d2x buildtools的bug
    现在已经修复了

    https://github.com/mcpp-community/d2mcpp/pull/40

    可以使用 d2x install d2mcpp 获取最新的项目 再尝试尝试

    注: 应该不是上面说的版本原因

  • 使用自编C++Web框架搭建的个人博客

    General Discussion | 综合讨论
    5
    0 赞同
    5 帖子
    132 浏览
    MineCodeM

    @unamed-coder 看https://glwebsite.us.ci/about下边的小字,我真不是福瑞

  • C/C++的神奇"语法", 趋向操作 `x --> 0`

    现代C++ | mcpp论坛
    3
    1 赞同
    3 帖子
    104 浏览
    unamed-coderU

    我怎么说没见过,原来是两个运算符的组合:-- 自减运算符和 > 大于运算符。

    先判断 x 是否大于0,若成立则 x 自减。这样 x 就会像 0 趋近,直到不大于 0。这种写法其实就是 (x--) > 0……

  • dx2命令无效

    现代C++ | mcpp论坛
    6
    0 赞同
    6 帖子
    86 浏览
    SPeakS

    具体参考

    http://forum.d2learn.org/post/774

    e0284a32-24d0-4bd1-98a7-df45b10c84e5-image.png

  • 0 赞同
    4 帖子
    148 浏览
    lost-42L

    看起来像是 ConsolePrint 和 encipherment 的问题, 错误提示有找不到模块 ConsolePrint 以及 encipherment 不是个命名空间.
    我没有用过这个库, 不确定是不是需要额外配置, 可以先替换成 std::println 试试?

  • 快速十六进制转八进制

    General Discussion | 综合讨论
    2
    1 赞同
    2 帖子
    78 浏览
    StehsaerS
    改进

    经过@yyq252517提醒并测试,直接使用12bit的查找表可以更快:

    consteval std::array<std::array<char, 4>, 4096> hex_to_oct_lookup() noexcept { std::array<std::array<char, 4>, 4096> lookup{}; for (size_t i = 0; i < 4096; ++i) { lookup[i][0] = '0' + ((i >> 0) & 0b111); lookup[i][1] = '0' + ((i >> 3) & 0b111); lookup[i][2] = '0' + ((i >> 6) & 0b111); lookup[i][3] = '0' + ((i >> 9) & 0b111); } return lookup; } // ... std::string hex_to_oct(const std::string& hex) noexcept { const auto hex_length = hex.length(); if (hex_length == 0) return "0"; const auto groups = (hex_length + 2) / 3; const auto oct_digits = groups * 4; std::string res(oct_digits, '0'); for (size_t i = hex_length % 3; i < hex_length; i += 3) { const size_t curr_group = (i + 2) / 3; const uint16_t h0 = hex_lookup[std::bit_cast<uint8_t>(hex[i + 2])]; // [3:0] const uint16_t h1 = hex_lookup[std::bit_cast<uint8_t>(hex[i + 1])]; // [7:4] const uint16_t h2 = hex_lookup[std::bit_cast<uint8_t>(hex[i + 0])]; // [11:8] const uint16_t idx = (h2 << 8) | (h1 << 4) | h0; // [11:0] const auto [o1, o2, o3, o4] = hex_to_oct_lookup_table[idx]; res[curr_group * 4 + 3] = o1; res[curr_group * 4 + 2] = o2; res[curr_group * 4 + 1] = o3; res[curr_group * 4 + 0] = o4; } if (hex_length % 3 != 0) { std::array<uint16_t, 3> h{0, 0, 0}; if (hex_length % 3 == 1) { h[0] = hex_lookup[std::bit_cast<uint8_t>(hex[0])]; } else // hex_length % 3 == 2 { h[1] = hex_lookup[std::bit_cast<uint8_t>(hex[0])]; h[0] = hex_lookup[std::bit_cast<uint8_t>(hex[1])]; } const uint16_t idx = (h[2] << 8) | (h[1] << 4) | h[0]; const auto [o1, o2, o3, o4] = hex_to_oct_lookup_table[idx]; res[3] = o1; res[2] = o2; res[1] = o3; res[0] = o4; } const auto first_non_zero = res.find_first_not_of('0'); if (first_non_zero == std::string::npos) return "0"; return res.substr(first_non_zero); }

    使用和此前一致的测试环境,可以得到:

    Optimized version: 72.16 ms (stddev: 0.45 ms), 1385897448.4948883 hex chars/sec

    比此前快了15%!此前低估了现代CPU的L1缓存系统的能力,看来它处理4096*4byte = 16KiB的查找表也不在话下

    感谢@yyq252517

  • 1 赞同
    2 帖子
    71 浏览
    woshinideba1425W

    错误例子(我写的)

    module; #include "httplib.h" export module mcp.compat.httplib; export namespace mcp { using HttpClient = httplib::Client; using DataSink = httplib::DataSink; using Headers = httplib::Headers; using HttpRequest = httplib::Request; using HttpResponse = httplib::Response; using HttpServer = httplib::Server; #ifdef MCP_SSL using SslServer = httplib::SSLServer; #endif }

    正确例子(官方库提供的)

    module; /* * Headers */ #ifdef _WIN32 #ifndef _CRT_SECURE_NO_WARNINGS #define _CRT_SECURE_NO_WARNINGS #endif //_CRT_SECURE_NO_WARNINGS #ifndef _CRT_NONSTDC_NO_DEPRECATE #define _CRT_NONSTDC_NO_DEPRECATE #endif //_CRT_NONSTDC_NO_DEPRECATE #if defined(_MSC_VER) #if _MSC_VER < 1900 #error Sorry, Visual Studio versions prior to 2015 are not supported #endif #pragma comment(lib, "ws2_32.lib") #ifndef _SSIZE_T_DEFINED #define _SSIZE_T_DEFINED #endif #endif // _MSC_VER #ifndef S_ISREG #define S_ISREG(m) (((m) & S_IFREG) == S_IFREG) #endif // S_ISREG #ifndef S_ISDIR #define S_ISDIR(m) (((m) & S_IFDIR) == S_IFDIR) #endif // S_ISDIR #ifndef NOMINMAX #define NOMINMAX #endif // NOMINMAX #include <io.h> #include <winsock2.h> #include <ws2tcpip.h> #if defined(__has_include) #if __has_include(<afunix.h>) // afunix.h uses types declared in winsock2.h, so has to be included after it. #include <afunix.h> #define CPPHTTPLIB_HAVE_AFUNIX_H 1 #endif #endif #ifndef WSA_FLAG_NO_HANDLE_INHERIT #define WSA_FLAG_NO_HANDLE_INHERIT 0x80 #endif #else // not _WIN32 #include <arpa/inet.h> #if !defined(_AIX) && !defined(__MVS__) #include <ifaddrs.h> #endif #ifdef __MVS__ #include <strings.h> #ifndef NI_MAXHOST #define NI_MAXHOST 1025 #endif #endif #include <net/if.h> #include <netdb.h> #include <netinet/in.h> #ifdef __linux__ #include <resolv.h> #undef _res // Undefine _res macro to avoid conflicts with user code (#2278) #endif #include <csignal> #include <netinet/tcp.h> #include <poll.h> #include <pthread.h> #include <sys/mman.h> #include <sys/socket.h> #include <sys/un.h> #include <unistd.h> #ifndef INVALID_SOCKET #define INVALID_SOCKET (-1) #endif #endif //_WIN32 #if defined(__APPLE__) #include <TargetConditionals.h> #endif #include <algorithm> #include <array> #include <atomic> #include <cassert> #include <cctype> #include <chrono> #include <climits> #include <condition_variable> #include <cstdlib> #include <cstring> #include <errno.h> #include <exception> #include <fcntl.h> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <memory> #include <mutex> #include <random> #include <regex> #include <set> #include <sstream> #include <string> #include <sys/stat.h> #include <system_error> #include <thread> #include <unordered_map> #include <unordered_set> #include <utility> #if defined(CPPHTTPLIB_USE_NON_BLOCKING_GETADDRINFO) || \ defined(CPPHTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN) #if TARGET_OS_MAC #include <CFNetwork/CFHost.h> #include <CoreFoundation/CoreFoundation.h> #endif #endif // CPPHTTPLIB_USE_NON_BLOCKING_GETADDRINFO or // CPPHTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN #ifdef CPPHTTPLIB_OPENSSL_SUPPORT #ifdef _WIN32 #include <wincrypt.h> // these are defined in wincrypt.h and it breaks compilation if BoringSSL is // used #undef X509_NAME #undef X509_CERT_PAIR #undef X509_EXTENSIONS #undef PKCS7_SIGNER_INFO #ifdef _MSC_VER #pragma comment(lib, "crypt32.lib") #endif #endif // _WIN32 #if defined(CPPHTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN) #if TARGET_OS_MAC #include <Security/Security.h> #endif #endif // CPPHTTPLIB_USE_NON_BLOCKING_GETADDRINFO #include <openssl/err.h> #include <openssl/evp.h> #include <openssl/ssl.h> #include <openssl/x509v3.h> #if defined(_WIN32) && defined(OPENSSL_USE_APPLINK) #include <openssl/applink.c> #endif #include <iostream> #include <sstream> #if defined(OPENSSL_IS_BORINGSSL) || defined(LIBRESSL_VERSION_NUMBER) #if OPENSSL_VERSION_NUMBER < 0x1010107f #error Please use OpenSSL or a current version of BoringSSL #endif #define SSL_get1_peer_certificate SSL_get_peer_certificate #elif OPENSSL_VERSION_NUMBER < 0x30000000L #error Sorry, OpenSSL versions prior to 3.0.0 are not supported #endif #endif // CPPHTTPLIB_OPENSSL_SUPPORT #ifdef CPPHTTPLIB_MBEDTLS_SUPPORT #include <mbedtls/ctr_drbg.h> #include <mbedtls/entropy.h> #include <mbedtls/error.h> #include <mbedtls/md5.h> #include <mbedtls/net_sockets.h> #include <mbedtls/oid.h> #include <mbedtls/pk.h> #include <mbedtls/sha1.h> #include <mbedtls/sha256.h> #include <mbedtls/sha512.h> #include <mbedtls/ssl.h> #include <mbedtls/x509_crt.h> #ifdef _WIN32 #include <wincrypt.h> #ifdef _MSC_VER #pragma comment(lib, "crypt32.lib") #endif #endif // _WIN32 #if defined(CPPHTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN) #if TARGET_OS_MAC #include <Security/Security.h> #endif #endif // CPPHTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN // Mbed TLS 3.x API compatibility #if MBEDTLS_VERSION_MAJOR >= 3 #define CPPHTTPLIB_MBEDTLS_V3 #endif #endif // CPPHTTPLIB_MBEDTLS_SUPPORT // Define CPPHTTPLIB_SSL_ENABLED if any SSL backend is available // This simplifies conditional compilation when adding new backends (e.g., // wolfSSL) #if defined(CPPHTTPLIB_OPENSSL_SUPPORT) || defined(CPPHTTPLIB_MBEDTLS_SUPPORT) #define CPPHTTPLIB_SSL_ENABLED #endif #ifdef CPPHTTPLIB_ZLIB_SUPPORT #include <zlib.h> #endif #ifdef CPPHTTPLIB_BROTLI_SUPPORT #include <brotli/decode.h> #include <brotli/encode.h> #endif #ifdef CPPHTTPLIB_ZSTD_SUPPORT #include <zstd.h> #endif export module httplib; export extern "C++" { #include "httplib.h" }

    当你试图将一个非模块化的第三方库(尤其是像 httplib 这种带全局状态或初始化逻辑的库)封装进模块时:

    不要尝试只导出部分类型:除非你非常确定该库没有全局初始化逻辑(Constructor static guards)。

    使用 export extern "C++":这是将传统头文件“模块化”的最标准、最稳妥做法。

    环境对齐:在 module; 之后,务必把该库依赖的所有系统宏(如 _WIN32, WIN32_LEAN_AND_MEAN 等)都写清楚。

  • 0 赞同
    4 帖子
    150 浏览
    fillSeaF

    @sunrisepeak 解决了👍

  • 【C++11】异步操作

    现代C++ | mcpp论坛
    2
    1 赞同
    2 帖子
    561 浏览
    SPeakS

    总结很好

  • 在CLion 2025.3.2中配置xmake项目

    FrozenLemonTee's Blog
    6
    3 赞同
    6 帖子
    258 浏览
    FrozenLemonTeeF

    @SPeak 具体没研究过,不过JetBrains的IDE集成程度比vscode高,可能不太能通过命令或者修改配置文件的方式来修改。如果有朋友有相关了解的可以贴在这里。

  • C++ 包管理器选哪个?

    已移动 现代C++ | mcpp论坛
    5
    0 赞同
    5 帖子
    180 浏览
    NekoycodeN

    除了vcpkg 和 xmake(xrepo) 的话, conan 比较受欢迎

  • 1 赞同
    6 帖子
    258 浏览
    sunrisepeakS

    @SkyWingF 后面给项目增加一个 类似 "最佳实践" 章节总结这些:

    类型别名用using 代替 typedef 引用的使用 尽量少使用宏 非必要不使用 属性标识 [[nodiscard]], [[deprecated]] ...