English 中文(简体)
C++双向表述媒介
原标题:Interweaving vector of binary representations in C++

我在C++中有一个称为“休妻”的模版功能,它有两个未经签名的char子,两个双双亲扩展,一个未签署。 它还可以带两个未签名的短信,并用两条双双亲的扩张来回远。 我在这里写道:

template<class Typeout, class Typein>
Typeout weave(Typein lhs,Typein rhs)
{
//Need to check that Typeout contains enough storage to contain 2*Typein:
assert(sizeof(Typeout)>=2*sizeof(Typein));

Typeout weaved = 0;
for(int k=0;k<sizeof(Typein)*8;k++)
{
    //weave in the kth element of rhs and lhs.
    weaved |=(Typeout(rhs & (Typein)(1<<k)) << k)| (Typeout(lhs & (Typein)(1<<k)) << (k+1));
}
return weaved;
};

现在,我与我们一道挖掘病媒。 我想写出一个称为“我们”的职能,它为我们的双亲扩张提供了各种果园。 举例来说,如果是没有签名的长度为4的载体,它就应当避免其双亲扩张,并恢复这方面的代表性。 我想为长于8年的病媒做这项工作,因此我不能再把他们长期搁置起来。 我猜想,我需要回到一个病媒? 但我不敢肯定如何削减由此产生的双轨扩张。

I m new to C++ so please feel free to correct the code or give me advice on it.

提前感谢。

问题回答

http://www.un.org。 我认为,你的问题是错误的(我经常说,“你”是你职位的实际问题。 如果问题是“我应作为参数来考虑,我应返回哪一类?”,那么你或许应当有<条码>const T*或const :vector< T>& para amount for submissions and another for production rather than Return, 这将避免分配-memory Owner problems.

// base case, weave two 8 bit into a 16 bit word.
uint16_t weave(uint8_t a, uint8_t b) {
    uint16_t x = a, y = b;
    x = (x | (x << 4)) & 0x0F0F;
    x = (x | (x << 2)) & 0x3333;
    x = (x | (x << 1)) & 0x5555;

    y = (y | (y << 4)) & 0x0F0F;
    y = (y | (y << 2)) & 0x3333;
    y = (y | (y << 1)) & 0x5555;

    return x | (y << 1);
}

// most useful way in my opinion
// weave bits from two arrays  a  and  b  of size n
// into a pre-allocated vector  out 
void weave(const char* a, const char* b, char* out, size_t n) {
    uint16_t* ret = (uint16_t*) out;

    for(size_t i = 0; i != n; ++i) {
        ret[i] = weave(a[i], b[i]);
    }
}

// template version, for those that like sugar
template<typename OUT, typename IN>
OUT weave(IN a, IN b, size_t n = 1) {
    OUT out;
    weave((char*) &a, (char*) &b, (char*) &out, sizeof(IN)*n);
    return out;
}

<>strong>DONTabes to Addeck, claim, et sobreto into production Code.





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签