- 1
typedef boost::shared_ptr<LPDIRECT3D9> Direct3dShared;
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+10
typedef boost::shared_ptr<LPDIRECT3D9> Direct3dShared;
Те кто знают, что такое в гейдеве LPDIRECT3D9 и IDirect3D9 - поймут.
Думаю сегодня даже не нужно писать с какого это сайта.
+16
QVector<Line> Converter::convert(QImage &image, Modes mode/*, int left, int top, int right, int bottom*/){
QVector<Line> result;
/* if(left < 0) left = 0;
if(top < 0) top = 0;
//if(right > image.width()) right = image.width();
//if(bottom > image.height()) bottom = image.height();
//points.clear();
//pix.fill(Qt::black);
if(left > right){
left ^= right;
right ^= left;
left ^= right;
}
if(top > bottom){
top ^= bottom;
bottom ^= top;
top ^= bottom;
}*/
int left = 0,top = 0,right = image.width(),bottom = image.height();
for( int i = left; i < right; ++i){
for( int j = top; j < bottom; ++j){
Line p;
p.x1 = p.x2 = i;
p.y1 = p.y2 = j;
p.z1 = qGray(image.pixel(i,j));
p.c = p.z1;
QVector<int> v;
if(i!=left) v.push_back(qGray(image.pixel(i-1,j)));
if(i < right-1) v.push_back(qGray(image.pixel(i+1,j)));
if(j!=top) v.push_back(qGray(image.pixel(i,j-1)));
if(j < bottom-1) v.push_back(qGray(image.pixel(i,j+1)));
if(i!=left && j!= top) v.push_back(qGray(image.pixel(i-1,j-1)));
if(i < right-1 && j!=top) v.push_back(qGray(image.pixel(i+1,j-1)));
if(j < bottom-1 && i!=left) v.push_back(qGray(image.pixel(i-1,j+1)));
if(i < right-1 && j < bottom-1) v.push_back(qGray(image.pixel(i+1,j+1)));
int min = *(std::min_element(v.begin(),v.end()));
if(min < qGray(image.pixel(i,j))){
/* for( unsigned k = 0; k < p.c-min; ++k){
Point p0;
p0.x = i;
p0.y = j;
p0.z = qGray(image.pixel(i,j))-(k+1);
p0.c = qGray(image.pixel(i,j));
points.push_back(p0);
}*/
p.z2 = p.z1 - min;
}else{
p.z2 = p.z1;
}
result.push_back(p);
}
}
/*origin.x = 0;
origin.y = 0;
origin.z = 0.0;*/
switch (mode) {
case ISO:
rotate(result, 3.1415/180*35.2,3.1415/4,-3.1415/4);
//rotate(result, 0,,0);
//rotate(result, 0,0,-3.1415/4);
break;
case BOTTOM:
rotate(result, 3.1415/180*90,0,0);
break;
case LEFT:
rotate(result, 3.1415/180*90,0,0);
rotate(result, 0, 3.1415/180*90,0);
break;
case RIGHT:
rotate(result, 3.1415/180*90,0,0);
rotate(result, 0, -3.1415/180*90,0);
break;
default:
break;
}
return result;
}
Картинка превращается, превращается...
+17
#include <iostream>
int main(){
int std = 10;
std::cout << std << std::endl;
}
+13
#include <iostream>
using namespace std;
// -- robot`s internal closed implementation --
int data1[] = { 0, 1, 2 }; char data2[] = { 42 };
// -- robot`s API
const int *GetMechaData1() { return data1; }
size_t GetMechaData1Size() { return 3; }
const char *GetMechaData2(){ return data2; }
size_t GetMechaData2Size() { return 1; }
// -- pentagon`s internal closed implementation --
//--------------------если T равно U, то результат будет D, а иначе - G------------//
template<class T, class U, class D, class G> struct SelectIF { typedef G type; };
template<class T, class D, class G> struct SelectIF<T, T, D, G> { typedef D type; };
// -- pentagon`s API
enum { eMAXBUFER = 200 * sizeof(int) };
template<class T, size_t N>void AcceptData(const T(&src)[N])
{
typedef typename SelectIF<T, char, int, T>::type Cast;
enum { is_char = std::is_same<T,char>::value };
cout << "received data:\n";
const size_t num = (N<eMAXBUFER) ? N : eMAXBUFER;
if (is_char)
for (size_t n = 0; n < num; ++n)
cout << "char code = " << (Cast)src[n] << " : char = '" << src[n] << "'\n";
else
for (size_t n = 0; n<num; ++n)
cout << "item = " << src[n] << endl;
}
// client code
template<class T, size_t N> struct Adapter
{
typedef Adapter<T, N + 1> Next;
void Pass(const T* data, const size_t num)
{
if (N < num)
{
Next().Pass(data, num);
return;
}
T(&arr)[N] = reinterpret_cast< T(&)[N] > (mBuf);
for (size_t n = 0; n< N; ++n) arr[n] = data[n];
AcceptData(arr);
}
size_t mLen;
T mBuf[eMAXBUFER];
};
template<class T> struct Adapter<T, eMAXBUFER>
{
void Pass(const T* data, const size_t)
{
for (size_t n = 0; n< eMAXBUFER; ++n) mBuf[n] = data[n];
AcceptData(mBuf);
}
size_t mLen;
T mBuf[eMAXBUFER];
};
Adapter<int, 1> adapter1;
Adapter<char, 1> adapter2;
int main()
{
{
const auto data = GetMechaData1();
const auto num = GetMechaData1Size();
adapter1.Pass(data, num);
}
{
const auto data = GetMechaData2();
const auto num = GetMechaData2Size();
adapter2.Pass(data, num);
}
}
Крестушки раскрестушились, а подраться не решились.
Под катом ещё несколько вариантов.
+7
#include <iostream>
#include <alloca.h>
#include <stdlib.h>
#include <new>
using namespace std;
int main(void) {
const size_t N = 5+rand()%4;
char* arr = ::new (alloca(N)) char[N]{1,2,3,4};
for(size_t i=0; i<N; ++i)
cout<<(int)arr[i]<<endl;
cout<<"ok";
return 0;
}
http://ideone.com/pax1TF
+5
auto q = db.exec("select name from sqlite_master where type='table'");
QStringList tables;
while(q.next()) {
tables.append(q.value(0).toString());
}
if(tables.contains("searchIndex")) {
types.insert(name, DASH);
} else {
types.insert(name, ZDASH);
}
Табличек в sqlite скорее всего мало и код должен работать довольно шустро.
Но сам подход достоен QHP
https://github.com/jkozera/zeal/blob/master/zeal/zealdocsetsregistry.cpp#L27
+15
#include <vector>
#include <iostream>
using namespace std;
// -- tools
// макет времени компиляции определяет количество элементов массива указанного в аргументе
template<class T, size_t N> char (&Size( T (&arr)[N] ) )[N];
// -- internal closed implementation --
int data1[] = {0, 1, 2};
char data2[] = {42};
const int ( &GetMechaData1() ) [ sizeof( Size(data1) ) ] { return data1; }
const char( &GetMechaData2() ) [ sizeof( Size(data2) ) ] { return data2; }
// -- API
//--- функции возвращают ссылки на массивы: например такого: const int[ sizeof( Size(data1) ]
const int ( &GetMechaData1() ) [ sizeof( Size(data1) ) ];
const char( &GetMechaData2() ) [ sizeof( Size(data2) ) ];
// client code
template<class T, size_t N> void ViewArray(const T (&arr)[N])
{
cout<<"data stored: \n";
for( auto& item: arr )
cout<< "item : "<<item<<endl;
}
int main()
{
ViewArray( GetMechaData1() );
ViewArray( GetMechaData2() );
return 0;
}
http://rextester.com/AEINWM88529
+64
#include <iostream>
#include <typeinfo>
struct Test {};
int main()
{
std::cout << typeid(int).name() << ", " << typeid(Test).name() << std::endl;
}
Очередные КРЕСТОПРОБЛЕМЫ.
MSVC: int, struct Test
GCC: i, 4Test
http://ideone.com/KPsIlP
Вот что говорит стандарт:
The class type_info describes type information generated by the implementation. Objects of this class effectively store a pointer to a name for the type, and an encoded value suitable for comparing two types for equality or collating order. The names, encoding rule, and collating sequence for types are all unspecified and may differ between programs.
RTTI ещё бесполезнее, чем я думала.
+21
template <int N>
void Ololo ()
{
var
i : integer;
begin
for i := 0 to N-1 do begin
WriteLn(i, ' ');
end;
end;
}
int main ()
{
return 0;
}
Compiling...
Test.cpp
Linking...
Build log was saved at "file://c:\Users\TarasB\Documents\Visual Studio Projects\Test\Debug\BuildLog.htm"
Test - 0 error(s), 0 warning(s)
---------------------- Done ----------------------
Build: 1 succeeded, 0 failed, 0 skipped
MSVS2003
+14
std::thread_fence(get_current_memory_order());