int main(int, char**) { #if TEST_STD_VER >= 11 { std::forward<A&>(source()); // expected-note {{requested here}} // expected-error-re@type_traits:* 1 {{static_assert failed{{.*}} "can not forward an rvalue as an lvalue"}} } #else { std::forward<A&>(source()); // expected-error {{no matching function for call to 'forward'}} } #endif { const A ca = A(); std::forward<A&>(ca); // expected-error {{no matching function for call to 'forward'}} } { std::forward<A&>(csource()); // expected-error {{no matching function for call to 'forward'}} } { const A ca = A(); std::forward<A>(ca); // expected-error {{no matching function for call to 'forward'}} } { std::forward<A>(csource()); // expected-error {{no matching function for call to 'forward'}} } { A a; std::forward(a); // expected-error {{no matching function for call to 'forward'}} } return 0; }
int main(int, char**) { A a; const A ca = A(); ((void)a); // Prevent unused warning ((void)ca); // Prevent unused warning static_assert(std::is_same<decltype(std::forward<A&>(a)), A&>::value, ""); static_assert(std::is_same<decltype(std::forward<A>(a)), A&&>::value, ""); static_assert(std::is_same<decltype(std::forward<A>(source())), A&&>::value, ""); static_assert(noexcept(std::forward<A&>(a)), ""); static_assert(noexcept(std::forward<A>(a)), ""); static_assert(noexcept(std::forward<A>(source())), ""); static_assert(std::is_same<decltype(std::forward<const A&>(a)), const A&>::value, ""); static_assert(std::is_same<decltype(std::forward<const A>(a)), const A&&>::value, ""); static_assert(std::is_same<decltype(std::forward<const A>(source())), const A&&>::value, ""); static_assert(noexcept(std::forward<const A&>(a)), ""); static_assert(noexcept(std::forward<const A>(a)), ""); static_assert(noexcept(std::forward<const A>(source())), ""); static_assert(std::is_same<decltype(std::forward<const A&>(ca)), const A&>::value, ""); static_assert(std::is_same<decltype(std::forward<const A>(ca)), const A&&>::value, ""); static_assert(std::is_same<decltype(std::forward<const A>(csource())), const A&&>::value, ""); static_assert(noexcept(std::forward<const A&>(ca)), ""); static_assert(noexcept(std::forward<const A>(ca)), ""); static_assert(noexcept(std::forward<const A>(csource())), ""); #if TEST_STD_VER > 11 { constexpr int i2 = std::forward<int>(42); static_assert(std::forward<int>(42) == 42, ""); static_assert(std::forward<const int&>(i2) == 42, ""); static_assert(test_constexpr_forward(), ""); } #endif #if TEST_STD_VER == 11 && defined(_LIBCPP_VERSION) // Test that std::forward is constexpr in C++11. This is an extension // provided by both libc++ and libstdc++. { constexpr int i2 = std::forward<int>(42); static_assert(std::forward<int>(42) == 42, "" ); static_assert(std::forward<const int&>(i2) == 42, ""); } #endif return 0; }
int main() { A a; const A ca = A(); #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES static_assert(sizeof(test(std::forward<A&>(a))) == 1, ""); static_assert(sizeof(test(std::forward<A>(a))) == 4, ""); static_assert(sizeof(test(std::forward<A>(source()))) == 4, ""); static_assert(sizeof(test(std::forward<const A&>(a))) == 2, ""); // static_assert(sizeof(test(std::forward<const A&>(source()))) == 2, ""); static_assert(sizeof(test(std::forward<const A>(a))) == 8, ""); static_assert(sizeof(test(std::forward<const A>(source()))) == 8, ""); static_assert(sizeof(test(std::forward<const A&>(ca))) == 2, ""); // static_assert(sizeof(test(std::forward<const A&>(csource()))) == 2, ""); static_assert(sizeof(test(std::forward<const A>(ca))) == 8, ""); static_assert(sizeof(test(std::forward<const A>(csource()))) == 8, ""); #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES static_assert(sizeof(test(std::forward<A&>(a))) == 1, ""); static_assert(sizeof(test(std::forward<A>(a))) == 1, ""); // static_assert(sizeof(test(std::forward<A>(source()))) == 2, ""); static_assert(sizeof(test(std::forward<const A&>(a))) == 2, ""); static_assert(sizeof(test(std::forward<const A&>(source()))) == 2, ""); static_assert(sizeof(test(std::forward<const A>(a))) == 2, ""); static_assert(sizeof(test(std::forward<const A>(source()))) == 2, ""); static_assert(sizeof(test(std::forward<const A&>(ca))) == 2, ""); static_assert(sizeof(test(std::forward<const A&>(csource()))) == 2, ""); static_assert(sizeof(test(std::forward<const A>(ca))) == 2, ""); static_assert(sizeof(test(std::forward<const A>(csource()))) == 2, ""); #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES #if _LIBCPP_STD_VER > 11 constexpr int i1 = std::move(23); static_assert(i1 == 23, "" ); constexpr int i2 = std::forward<int>(42); static_assert(i2 == 42, "" ); #endif }
int main() { // std::cout << " ------ test 1, direct init from rvalue ------- " << std::endl; // #if defined(__GNUC__) && 0 // GCC having trouble parsing the extra parens // X z2((0, X() )); // #else X z2((X())); // #endif // std::cout << " ------ test 2, copy init from rvalue ------- " << std::endl; X z4 = X(); // std::cout << " ------ test 3, copy init from lvalue ------- " << std::endl; X z5 = z4; // std::cout << " ------ test 4, direct init from lvalue ------- " << std::endl; X z6(z4); // std::cout << " ------ test 5, construct const ------- " << std::endl; X const z7; // std::cout << " ------ test 6, copy init from lvalue ------- " << std::endl; X z8 = z7; // std::cout << " ------ test 7, direct init from lvalue ------- " << std::endl; X z9(z7); // std::cout << " ------ test 8, pass rvalue by-value ------- " << std::endl; sink(source()); // std::cout << " ------ test 9, pass const rvalue by-value ------- " << std::endl; sink(csource()); // std::cout << " ------ test 10, pass rvalue by overloaded reference ------- " << std::endl; // This one fails in Comeau's strict mode due to 8.5.3/5. GCC 3.3.1 passes it. sink2(source()); // std::cout << " ------ test 11, pass const rvalue by overloaded reference ------- " << std::endl; sink2(csource()); #if 0 // These two correctly fail to compile, just as desired std::cout << " ------ test 12, pass rvalue by non-const reference ------- " << std::endl; sink3(source()); std::cout << " ------ test 13, pass const rvalue by non-const reference ------- " << std::endl; sink3(csource()); #endif // std::cout << " ------ test 14, pass lvalue by-value ------- " << std::endl; sink(z5); // std::cout << " ------ test 15, pass const lvalue by-value ------- " << std::endl; sink(z7); // std::cout << " ------ test 16, pass lvalue by-reference ------- " << std::endl; sink2(z4); // std::cout << " ------ test 17, pass const lvalue by const reference ------- " << std::endl; sink2(z7); // std::cout << " ------ test 18, pass const lvalue by-reference ------- " << std::endl; #if 0 // correctly fails to compile, just as desired sink3(z7); #endif // std::cout << " ------ test 19, pass rvalue by value to template param ------- " << std::endl; tsink(source()); // std::cout << " ------ test 20, direct initialize a const A with an A ------- " << std::endl; typedef X const XC; sink2(XC(X())); // std::cout << " ------ test 21, assign from lvalue ------- " << std::endl; z4 = z5; // std::cout << " ------ test 22, assign from rvalue ------- " << std::endl; z4 = source(); }
int main() { std::forward<A&>(csource()); // error }
int Model::init(){ if(this->queueEvent_.downloadDataFun_) space.copyDataToSpace(); // else //tu bedzie wczytywanie przestrzeni z pliku compCore.init(); // compCore.memoryManager_.createBuffers(); // tu definicja rand for(unsigned int k = 0; k<rules.rulesList_.size();++k){ Rule * rule = rules.rulesList_[k]; kernManager.addDefinition("DIMENSION", space.dimension_); // Dodawanie definicji wielkosci w zaleznosci od wymiaru przestrzeni if(space.boundaryCondition_ == ca::Space::PERIODIC_CONDITION) // Ustawienie warunku brzegowego w kernelu kernManager.addDefinition("PERIODIC_CONDITION", ""); else if(space.boundaryCondition_ == ca::Space::CLOSED_ABSORBING_CONDITION) kernManager.addDefinition("CLOSED_ABSORBING_CONDITION", ""); int numCell = space.size_[0]; kernManager.addDefinition("X_SIZE", space.size_[0]); if(space.dimension_ > 1){ kernManager.addDefinition("Y_SIZE", space.size_[1]); numCell *= space.size_[1]; if(space.dimension_ > 2){ kernManager.addDefinition("Z_SIZE", space.size_[2]); numCell *= space.size_[2]; } } kernManager.addDefinition("NUM_CELLS", space.numCells_); kernManager.addDefinition("NUM_CELLS_INTS", space.numCellsInts_); kernManager.addDefinition("NUM_CELLS_REAL", space.numCellsReals_); kernManager.addDefinition("NUM_GRAINS_INTS", space.numGrainsInts_); kernManager.addDefinition("NUM_GRAINS_REAL", space.numGrainsReals_); kernManager.addDefinition("NUM_SPACE_INTS", space.numSpaceInts_); kernManager.addDefinition("NUM_SPACE_REALS", space.numSpaceReals_); kernManager.addDefinition("NUM_SPACE_PART", compCore.devices_.size()); kernManager.createKernel(rule); // TODO tymczasowe obliczanie fragmentow std::string csource(this->kernManager.sources_[0]); this->kernManager.sources_.clear(); std::string tsource = ""; long tempPart = 0; compCore.memoryManager_.createBuffers(); for (unsigned int nr = 0; nr < (compCore.devices_.size()); ++nr) { long nrlinesParts = static_cast<long>(space.size_[1]/(compCore.devices_.size()) + 0.9 + kernManager.neighincl_ - 1); std::string number = ""; std::stringstream strstream1,strstream2,strstream3,strstream4,strstream5,strstream6,strstream7; tempPart = static_cast<long>(nr * nrlinesParts - 1); if(nr == 0) ++tempPart; compCore.memoryManager_.begParts_.push_back(tempPart); strstream4 << tempPart; strstream4 >> number; tsource = "\n#define FIRST_ROW_PART_WITH_NEIGH " + number; tempPart = nr * (space.size_[1]/(compCore.devices_.size())); strstream1 << tempPart; strstream1 >> number; tsource += "\n#define FIRST_ROW_PART " + number; tempPart = static_cast<long>((long)(nr+1)*nrlinesParts ); if(nr == compCore.devices_.size() - 1) --tempPart; compCore.memoryManager_.endParts_.push_back(tempPart); strstream2 << tempPart; number = ""; strstream2 >> number; tsource += "\n#define LAST_ROW_PART_WITH_NEIGH " + number; tempPart = (nr+1) * (space.size_[1]/(compCore.devices_.size())) -1; strstream5 << tempPart; strstream5 >> number; tsource += "\n#define LAST_ROW_PART " + number; tempPart = static_cast<long>(nrlinesParts * space.size_[0]); compCore.memoryManager_.numCellPart_.push_back(tempPart); strstream6 << tempPart; number = ""; strstream6 >> number; tsource += "\n#define NUM_CELL_PART " + number; tempPart = static_cast<long>(nrlinesParts); compCore.memoryManager_.numCellPart_.push_back(tempPart); strstream3 << tempPart; number = ""; strstream3 >> number; tsource += "\n#define NUM_ROW_PART " + number; tempPart = kernManager.neighincl_; if(nr==0) tempPart = 0; strstream7 << tempPart; strstream7 >> number; tsource += "\n#define NEIGH_DEPTH_BEG " + number; tsource += "\n" + csource; kernManager.sources_.push_back(tsource); std::cout << tsource << "\n\n"; } for (unsigned int var = 0; var < compCore.devices_.size(); ++var) { kernManager.compileKernel(var, *compCore.devices_[var]); } for (unsigned int var = 0; var < compCore.devices_.size(); ++var) { int err; compCore.devices_[var]->commandQueue_ = cl::CommandQueue(compCore.devices_[var]->platform_->context_,*compCore.devices_[var]->coreDevice_,0,&err); } } return 0; }
bool Warp::accelerated_cairorender(Context context, cairo_t *cr, int quality, const RendDesc &renddesc_, ProgressCallback *cb)const { Point src_tl=param_src_tl.get(Point()); Point src_br=param_src_br.get(Point()); Point dest_tl=param_dest_tl.get(Point()); Point dest_tr=param_dest_tr.get(Point()); Point dest_bl=param_dest_bl.get(Point()); Point dest_br=param_dest_br.get(Point()); Real horizon=param_horizon.get(Real()); bool clip=param_clip.get(bool()); SuperCallback stageone(cb,0,9000,10000); SuperCallback stagetwo(cb,9000,10000,10000); RendDesc renddesc(renddesc_); // Untransform the render desc if(!cairo_renddesc_untransform(cr, renddesc)) return false; Real pw=(renddesc.get_w())/(renddesc.get_br()[0]-renddesc.get_tl()[0]); Real ph=(renddesc.get_h())/(renddesc.get_br()[1]-renddesc.get_tl()[1]); if(cb && !cb->amount_complete(0,10000)) return false; Point tl(renddesc.get_tl()); Point br(renddesc.get_br()); Rect bounding_rect; Rect render_rect(tl,br); Rect clip_rect(Rect::full_plane()); Rect dest_rect(dest_tl,dest_br); dest_rect.expand(dest_tr).expand(dest_bl); Real zoom_factor(1.0); // Quick exclusion clip, if necessary if(clip && !intersect(render_rect,dest_rect)) { cairo_save(cr); cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR); cairo_paint(cr); cairo_restore(cr); return true; } { Rect other(render_rect); if(clip) other&=dest_rect; Point min(other.get_min()); Point max(other.get_max()); bool init_point_set=false; // Point trans_point[4]; Point p; // Real trans_z[4]; Real z,minz(10000000000000.0f),maxz(0); //! \todo checking the 4 corners for 0<=z<horizon*2 and using //! only 4 corners which satisfy this condition isn't the //! right thing to do. It's possible that none of the 4 //! corners fall within that range, and yet content of the //! tile does. p=transform_forward(min); z=transform_backward_z(p); if(z>0 && z<horizon*2) { if(init_point_set) bounding_rect.expand(p); else bounding_rect=Rect(p); init_point_set=true; maxz=std::max(maxz,z); minz=std::min(minz,z); } p=transform_forward(max); z=transform_backward_z(p); if(z>0 && z<horizon*2) { if(init_point_set) bounding_rect.expand(p); else bounding_rect=Rect(p); init_point_set=true; maxz=std::max(maxz,z); minz=std::min(minz,z); } swap(min[1],max[1]); p=transform_forward(min); z=transform_backward_z(p); if(z>0 && z<horizon*2) { if(init_point_set) bounding_rect.expand(p); else bounding_rect=Rect(p); init_point_set=true; maxz=std::max(maxz,z); minz=std::min(minz,z); } p=transform_forward(max); z=transform_backward_z(p); if(z>0 && z<horizon*2) { if(init_point_set) bounding_rect.expand(p); else bounding_rect=Rect(p); init_point_set=true; maxz=std::max(maxz,z); minz=std::min(minz,z); } if(!init_point_set) { cairo_save(cr); cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR); cairo_paint(cr); cairo_restore(cr); return true; } zoom_factor=(1+(maxz-minz)); } #ifdef ACCEL_WARP_IS_BROKEN return Layer::accelerated_cairorender(context,cr,quality,renddesc, cb); #else /*swap(tl[1],br[1]); bounding_rect .expand(transform_forward(tl)) .expand(transform_forward(br)) ; swap(tl[1],br[1]);*/ //synfig::warning("given window: [%f,%f]-[%f,%f] %dx%d",tl[0],tl[1],br[0],br[1],renddesc.get_w(),renddesc.get_h()); //synfig::warning("Projected: [%f,%f]-[%f,%f]",bounding_rect.get_min()[0],bounding_rect.get_min()[1],bounding_rect.get_max()[0],bounding_rect.get_max()[1]); // If we are clipping, then go ahead and clip to the // source rectangle if(clip) clip_rect&=Rect(src_tl,src_br); // Bound ourselves to the bounding rectangle of // what is under us clip_rect&=context.get_full_bounding_rect();//.expand_x(abs(zoom_factor/pw)).expand_y(abs(zoom_factor/ph)); bounding_rect&=clip_rect; Point min_point(bounding_rect.get_min()); Point max_point(bounding_rect.get_max()); // we're going to divide by the difference of these pairs soon; // if they're the same, we'll be dividing by zero, and we don't // want to do that! // \todo what should we do in this case? if (min_point[0] == max_point[0]) max_point[0] += 0.001; if (min_point[1] == max_point[1]) max_point[1] += 0.001; if(tl[0]>br[0]) { tl[0]=max_point[0]; br[0]=min_point[0]; } else { br[0]=max_point[0]; tl[0]=min_point[0]; } if(tl[1]>br[1]) { tl[1]=max_point[1]; br[1]=min_point[1]; } else { br[1]=max_point[1]; tl[1]=min_point[1]; } const int tmp_d(max(renddesc.get_w(),renddesc.get_h())); Real src_pw=(tmp_d*zoom_factor)/(br[0]-tl[0]); Real src_ph=(tmp_d*zoom_factor)/(br[1]-tl[1]); RendDesc desc(renddesc); desc.clear_flags(); //desc.set_flags(RendDesc::PX_ASPECT); desc.set_tl(tl); desc.set_br(br); desc.set_wh(ceil_to_int(src_pw*(br[0]-tl[0])),ceil_to_int(src_ph*(br[1]-tl[1]))); //synfig::warning("surface to render: [%f,%f]-[%f,%f] %dx%d",desc.get_tl()[0],desc.get_tl()[1],desc.get_br()[0],desc.get_br()[1],desc.get_w(),desc.get_h()); if(desc.get_w()==0 && desc.get_h()==0) { cairo_save(cr); cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR); cairo_paint(cr); cairo_restore(cr); return true; } // Recalculate the pixel widths for the src renddesc src_pw=(desc.get_w())/(desc.get_br()[0]-desc.get_tl()[0]); src_ph=(desc.get_h())/(desc.get_br()[1]-desc.get_tl()[1]); cairo_surface_t* source=cairo_surface_create_similar(cairo_get_target(cr), CAIRO_CONTENT_COLOR_ALPHA, desc.get_w(),desc.get_h()); cairo_surface_t* surface=cairo_surface_create_similar(cairo_get_target(cr), CAIRO_CONTENT_COLOR_ALPHA,renddesc.get_w(), renddesc.get_h()); cairo_t* subcr=cairo_create(source); cairo_scale(subcr, 1/desc.get_pw(), 1/desc.get_ph()); cairo_translate(subcr, -desc.get_tl()[0], -desc.get_tl()[1]); if(!context.accelerated_cairorender(subcr,quality,desc,&stageone)) return false; cairo_destroy(subcr); int surfacew, surfaceh, sourcew, sourceh; CairoSurface csurface(surface); CairoSurface csource(source); csurface.map_cairo_image(); csource.map_cairo_image(); surfacew=csurface.get_w(); surfaceh=csurface.get_h(); sourcew=csource.get_w(); sourceh=csource.get_h(); CairoSurface::pen pen(csurface.begin()); // Do the warp { int x,y; float u,v; Point point,tmp; for(y=0,point[1]=renddesc.get_tl()[1];y<surfaceh;y++,pen.inc_y(),pen.dec_x(x),point[1]+=1.0/ph) { for(x=0,point[0]=renddesc.get_tl()[0];x<surfacew;x++,pen.inc_x(),point[0]+=1.0/pw) { tmp=transform_forward(point); const float z(transform_backward_z(tmp)); if(!clip_rect.is_inside(tmp) || !(z>0 && z<horizon)) { csurface[y][x]=Color::alpha(); continue; } u=(tmp[0]-tl[0])*src_pw; v=(tmp[1]-tl[1])*src_ph; if(u<0 || v<0 || u>=sourcew || v>=sourceh || isnan(u) || isnan(v)) csurface[y][x]=context.get_cairocolor(tmp); else { // CUBIC if(quality<=4) csurface[y][x]=csource.cubic_sample_cooked(u,v); // INTEPOLATION_LINEAR else if(quality<=6) csurface[y][x]=csource.linear_sample_cooked(u,v); else // NEAREST_NEIGHBOR csurface[y][x]=csource[floor_to_int(v)][floor_to_int(u)]; } } if((y&31)==0 && cb) { if(!stagetwo.amount_complete(y,surfaceh)) return false; } } } #endif if(cb && !cb->amount_complete(10000,10000)) return false; csurface.unmap_cairo_image(); csource.unmap_cairo_image(); cairo_surface_destroy(source); cairo_save(cr); cairo_translate(cr, renddesc.get_tl()[0], renddesc.get_tl()[1]); cairo_scale(cr, renddesc.get_pw(), renddesc.get_ph()); cairo_set_source_surface(cr, surface, 0, 0); cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); cairo_paint(cr); cairo_restore(cr); cairo_surface_destroy(surface); return true; }