几天前,我遇到了这个用于Base-36编码字节数组的CodeReview.但是,接下来的答案没有触及解码回字节数组,或者可能重复使用答案来执行不同基数(基数)的编码.
链接问题的答案使用BigInteger.因此,就实现而言,可以对基数及其数字进行参数化.
但是,BigInteger的问题在于我们将输入视为假定的整数.但是,我们的输入(字节数组)只是一系列不透明的值.
.NET程序员如何使用BigInteger创建一个合理有效且基数不可知的编码器,具有解码支持,以及处理字节序的能力,以及"解决"结束零字节丢失的能力?
在尝试制定C宏以简化非const成员函数的编写时,使用完全相同的逻辑调用const成员函数(参见第1章,第3项,"在有效C++中避免const和非const成员函数中的重复" ),我相信我decltype()在VS2013 Update 1中遇到了一个错误.
我想用来在前面提到的宏中decltype(*this)构建一个static_cast<decltype(*this) const&>(*this)表达式,以避免宏调用站点传递任何显式类型信息.但是,在VS2013的某些情况下,后一个表达式似乎没有正确地添加const.
这是一小块代码,我能够回复这个bug:
#include <stdio.h>
template<typename DatumT>
struct DynamicArray
{
DatumT* elements;
unsigned element_size;
int count;
inline const DatumT* operator [](int index) const
{
if (index < 0 || index >= count)
return nullptr;
return &elements[index];
}
inline DatumT* operator [](int index)
{
#if defined(MAKE_THIS_CODE_WORK)
DynamicArray const& _this = static_cast<decltype(*this) const&>(*this);
return const_cast<DatumT*>(_this[index]);
#else
// warning C4717: 'DynamicArray<int>::operator[]' : recursive on all control paths, function will cause runtime …Run Code Online (Sandbox Code Playgroud)