所以我有一个Random对象:
typedef unsigned int uint32;
class Random {
public:
Random() = default;
Random(std::mt19937::result_type seed) : eng(seed) {}
private:
uint32 DrawNumber();
std::mt19937 eng{std::random_device{}()};
std::uniform_int_distribution<uint32> uniform_dist{0, UINT32_MAX};
};
uint32 Random::DrawNumber()
{
return uniform_dist(eng);
}
Run Code Online (Sandbox Code Playgroud)
什么是我可以改变(通过另一个函数或其他方式)分布的上限的最佳方式?
(也愿意就其他风格问题提出建议)
我正在将构建系统从configure/make转换为cmake系统
该系统有一些自动生成的文件,来自bison/flex.原始的makefile命令是:
bison --defines=tokens.h --output=parser.cpp parser.y
flex --outfile=scanner.cpp scanner.l
Run Code Online (Sandbox Code Playgroud)
我遇到了这个古老的链接,似乎解释了如何做到这一点,但是当我使用以下自定义命令运行cmake时,似乎没有任何事情发生(没有错误消息,没有文件生成)
FIND_PACKAGE(BISON REQUIRED)
IF(BISON_FOUND)
ADD_CUSTOM_COMMAND(
SOURCE ${CMAKE_SOURCE_DIR}/src/rcdgen/parser.y
COMMAND ${BISON_EXECUTABLE}
ARGS --defines=${CMAKE_SOURCE_DIR}/src/rcdgen/tokens.h
-o ${CMAKE_SOURCE_DIR}/src/rcdgen/parser.cpp
${CMAKE_SOURCE_DIR}/src/rcdgen/parser.y
COMMENT "Generating parser.cpp"
OUTPUT ${CMAKE_SOURCE_DIR}/src/rcdgen/parser.cpp
)
ENDIF(BISON_FOUND)
FIND_PACKAGE(FLEX REQUIRED)
IF(FLEX_FOUND)
ADD_CUSTOM_COMMAND(
SOURCE ${CMAKE_SOURCE_DIR}/src/rcdgen/scanner.l
COMMAND ${FLEX_EXECUTABLE}
ARGS -o${CMAKE_SOURCE_DIR}/src/rcdgen/parser.cpp
${CMAKE_SOURCE_DIR}/src/rcdgen/scanner.l
COMMENT "Generating scanner.cpp"
OUTPUT ${CMAKE_SOURCE_DIR}/src/rcdgen/scanner.cpp
)
ENDIF(FLEX_FOUND)
Run Code Online (Sandbox Code Playgroud)
我是cmake的新手,所以这对我来说有点混乱.有没有人知道什么是有效的custom_command?
我不完全确定这是最好的地方,但我想不出更好的地方
我已经"制作"了一种低分辨率的字体.(奖励积分,如果你知道它实际来自哪里)
字体在gedit中工作正常: 
但是,当尝试使用SDL_ttf渲染字体时,除了一些多字节unicode字符(特别是' æ '和' ℃ ')之外,它主要起作用,而其他非ASCII字符工作正常.但是(!),所有这些字符都适用于其他字体(我一直在使用DejaVu Sans)

其他字体工作正常的事实表明代码不应该受到责备,但以防万一:
SDL_Surface *surf = TTF_RenderUTF8_Solid(this->font, (const char *)text, col);
if (surf == nullptr) {
fprintf(stderr, "Rendering text failed (%s)\n", TTF_GetError());
return;
}
if (surf->format->BitsPerPixel != 8 || surf->format->BytesPerPixel != 1) {
fprintf(stderr, "Rendering text failed (Wrong surface format)\n");
return;
}
Run Code Online (Sandbox Code Playgroud)
(text is const uint8*)显然没有触发这些错误
我注意到这两个角色特别比其他角色更广泛,这可能是罪魁祸首吗?
根据下面的评论,字体似乎与SDL_TTF"latin-1"演示一起正常工作:

>>> from ctypes import *
>>> import ctypes.util
>>> libc = CDLL("libc.so.6")
>>> libc.printf("%c\n", 104)
h
2
>>> libc.islower(104) # Works fine
512
>>> libc.islower.restype = c_bool # But when i do this...
>>> libc.islower(104)
False
>>> c_bool(512)
c_bool(True)
Run Code Online (Sandbox Code Playgroud)
就个人而言,我认为'h'是小写的..
这是ctypes中的错误,还是我做错了什么?
我正在制作一个WinForms程序,它需要单独的线程为了可读性和可维护性,我将所有非GUI代码分离到不同的类中.这个类还"生成"另一个类,它进行一些处理.但是,我现在遇到了一个问题,我需要从一个在另一个类中启动的线程更改WinForms控件(将字符串附加到文本框)
我已经四处搜索,并找到了不同线程的解决方案,并且在不同的类中,但不是两者兼而有之,所提供的解决方案似乎不兼容(对我而言)
这可能是最大的"领先":如何从另一个类中运行的另一个线程更新UI
类层次结构示例:
class WinForm : Form
{
...
Server serv = new Server();
}
// Server is in a different thread to winform
class Server
{
...
ClientConnection = new ClientConnection();
}
// Another new thread is created to run this class
class ClientConnection
{
//Want to modify winform from here
}
Run Code Online (Sandbox Code Playgroud)
我知道事件处理程序可能是要走的路,但在这种情况下我无法弄清楚如何这样做(我也愿意接受其他建议;))
任何帮助赞赏
我在Ada中遇到了一些泛型问题.鉴于以下示例,gnatmake导致:
g_package.adb:13:33: 'Access attribute not allowed in generic body
g_package.adb:13:33: because access type "t_callback_p" is declared outside generic unit (RM 3.10.2(32))
g_package.adb:13:33: move 'Access to private part, or (Ada 2005) use anonymous access type instead of "t_callback_p"
gnatmake: "g_package.adb" compilation error
Run Code Online (Sandbox Code Playgroud)
假设外部包不能更改,有没有办法解决这个问题?我首先得到了错误消息的原因(编译器不知道通用包的正确类型,但是当传递的函数没有触及泛型的任何部分时,它有点烦人.)
g_package.adb
with Ada.Text_IO; use Ada.Text_IO;
with external;
package body g_package is
procedure quix (f : String) is
begin
Put_Line ("Does a thing");
end quix;
procedure foo (bar : String) is
begin
Put_Line ("baz" & bar & Boolean'Image(flag));
external.procedure_f …Run Code Online (Sandbox Code Playgroud)