當前位置: 首頁>>代碼示例>>C++>>正文


C++ std::fill方法代碼示例

本文整理匯總了C++中std::fill方法的典型用法代碼示例。如果您正苦於以下問題:C++ std::fill方法的具體用法?C++ std::fill怎麽用?C++ std::fill使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在std的用法示例。


在下文中一共展示了std::fill方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。

示例1: main

int main()
{
	vector<int>ivec(10);		//default initialized to 0
	fill(ivec.begin(), ivec.end(), 1);		//reset each element to 1

	//print elements in ivec
	auto iter = ivec.begin();
	while (iter != ivec.end())
		cout << *iter++ << " ";
	cout << endl;
	//sum the elements in ivec starting the summation with the value 0
	int sum = accumulate(ivec.begin(), ivec.end(), 0);
	cout << sum << endl;

	//set a subsequence of the container to 10
	fill(ivec.begin(), ivec.begin() + ivec.size() / 2, 10);
	cout << accumulate(ivec.begin(), ivec.end(), 0) << endl;

	//reset the same subsequence to 0
	fill_n(ivec.begin(), ivec.size() / 2, 0);
	cout << accumulate(ivec.begin(), ivec.end(), 0) << endl;

	//concatenates elements	in a vector of strings and store in sum
	vector<string>v;
	string s;
	while (cin >> s)
		v.push_back(s);
	string concat = accumulate(v.begin(), v.end(), string(""));
	cout << concat << endl;
	getchar();
}
開發者ID:Larry955,項目名稱:learnCPP,代碼行數:31,代碼來源:accum.cpp

示例2: main

int main()
{
	vector<int> vec(10);              // default initialized to 0
	fill(vec.begin(), vec.end(), 1);  // reset each element to 1

	// sum the elements in vec starting the summation with the value 0
	int sum = accumulate(vec.cbegin(), vec.cend(), 0);
	cout << sum << endl;
	
	// set a subsequence of the container to 10
	fill(vec.begin(), vec.begin() + vec.size()/2, 10);
	cout << accumulate(vec.begin(), vec.end(), 0) << endl;

	// reset the same subsequence to 0
	fill_n(vec.begin(), vec.size()/2, 0);
	cout << accumulate(vec.begin(), vec.end(), 0) << endl;

	// create 10 elements on the end of vec each with the value 42
	fill_n(back_inserter(vec), 10, 42);
	cout << accumulate(vec.begin(), vec.end(), 0) << endl;
	
	// concatenate elements in a vector of strings and store in sum 
	vector<string> v;
	string s;
	while (cin >> s)
		v.push_back(s);
	string concat = accumulate(v.cbegin(), v.cend(), string(""));
	cout << concat << endl;
	
	return 0;
}
開發者ID:MGZX,項目名稱:cpp_primer,代碼行數:31,代碼來源:accum.cpp

示例3: if

void
ZeroCopyDataSeq<Sample_T, DEF_MAX>::length(CORBA::ULong length)
{
  using std::fill;
  using std::max;
  using std::copy;

  if (length == this->length())
  {
    return;
  }

  if (is_zero_copy())
    {
      if (length < ptrs_.size())
        {
          if (!loaner_)
            {
              make_single_copy(length);
              this->length(length);
              return;
            }
          for (size_t i(length); i < ptrs_.size(); ++i)
            {
              --ptrs_[i]->zero_copy_cnt_;
              loaner_->dec_ref_data_element(ptrs_[i]);
            }
          ptrs_.resize(length, 0);
        }
      else
        {
          //There's no way we can expand the size (logical) of the zero-copy
          //array and have the user do any meaningful operations on the new
          //elements.  The fact that they're pointers to ReceivedDataElement
          //is hidden from the user.  Thus we need to make the sequence
          //single-copy at this point.
          make_single_copy(length);
        }
    }
  else
    {
      if (length < sc_length_) //shrink
        {
          sc_length_ = length;
        }
      else if (length <= sc_maximum_) //grow within buffer
        {
          fill(&sc_buffer_[sc_length_], &sc_buffer_[length], Sample_T());
          sc_length_ = length;
        }
      else //grow to larger buffer
        {
          ZeroCopyDataSeq<Sample_T, DEF_MAX> grow(max(length, sc_maximum_*2));
          copy(sc_buffer_, &sc_buffer_[sc_length_], grow.sc_buffer_);
          fill(&grow.sc_buffer_[sc_length_], &grow.sc_buffer_[length],
            Sample_T());
          swap(grow);
        }
    }
}
開發者ID:svn2github,項目名稱:OpenDDS,代碼行數:60,代碼來源:ZeroCopySeq_T.cpp

示例4: fill

Ksf::Ksf(void)  :   m_madi( 0 ), 
    m_tick( 0 ),
    m_dummy( 0 ),
    m_track( 0 )
{
    fill( &m_bpm[0], &m_bpm[3], 0.0 );
    fill( &m_start[0], &m_start[3], 0 );
    fill( &m_bunki[0], &m_bunki[2], 0 );
}
開發者ID:beebopkim,項目名稱:KickItUp,代碼行數:9,代碼來源:Ksf.cpp

示例5: FillBoundary

	void FillBoundary(unsigned char* image_out, int w, int h, int bpp)
	{
		const int line_stride = bpp*w;
		fill(image_out, image_out+line_stride, 0);
		for (int y = 1; y < h-1; ++y) {
			fill(image_out, image_out+bpp, 0);
			fill(image_out+line_stride-bpp, image_out+line_stride, 0);
			image_out += line_stride;
		}
		fill(image_out, image_out+line_stride, 0);
	}
開發者ID:JieFangD,項目名稱:Orientation,代碼行數:11,代碼來源:main.cpp

示例6: test

bool test(const Problem<Scalar> &p)
{
    BOOST_TEST_MESSAGE("Testing problem " << p);

    typedef typename suzerain::traits::component<Scalar>::type component_type;
    using suzerain::complex::traits::is_complex;
    using std::abs;
    using std::copy;
    using std::fill;
    using std::partial_sum;
    using std::sqrt;

    const int N = p.S*p.n;

    // Allocate working storage
    suzerain::scoped_array<Scalar> x(new Scalar[N*abs(p.incx)]);
    suzerain::scoped_array<Scalar> y(new Scalar[N*abs(p.incy)]);
    suzerain::scoped_array<Scalar> r(new Scalar[N*abs(p.incy)]);

    // Synthesize test data
    fill(x.get(), x.get() + N*abs(p.incx), p.alpha+p.alpha+Scalar(1));
    if (is_complex<Scalar>::value) {
         fill(y.get(), y.get() + N*abs(p.incy),
              p.alpha-Scalar(7) + sqrt(Scalar(-1)));
    } else {
         fill(y.get(), y.get() + N*abs(p.incy),
              p.alpha-Scalar(7));
    }
    partial_sum(x.get(), x.get() + N*abs(p.incx), x.get());
    partial_sum(y.get(), y.get() + N*abs(p.incy), y.get());
    copy(y.get(), y.get() + N*abs(p.incy), r.get());

    // Compute the single-shot result using BSMBSM routines
    aPxpby(p, x.get(), r.get());

    // Compute same result by permuting followed by axpby
    suzerain::shared_ptr<gsl_permutation> g(suzerain_bsmbsm_permutation(p.S,p.n),
                                            &gsl_permutation_free);
    permute(p, g.get(), x.get());
    suzerain::blas::axpby(N, p.alpha, x.get(), p.incx,
                             p.beta,  y.get(), p.incy);

    // Cook a reasonable agreement tolerance
    component_type tol = std::numeric_limits<component_type>::epsilon();
    if (is_complex<Scalar>::value) tol *= 4;

    // Do r (from aPxpby) and y (from permute/axpby) agree?
    return check_close_collections(r.get(), r.get() + N*abs(p.incy),
                                   y.get(), y.get() + N*abs(p.incy),
                                   tol);
}
開發者ID:RhysU,項目名稱:suzerain,代碼行數:51,代碼來源:test_bsmbsm.cpp

示例7: fill

void fill(symmetric_canvas<uint8_t> *grid1,symmetric_canvas<uint8_t> *grid2,
	double alpha, double exponent, double thickness, double sharpness,stripes_grid &sgr)
{
	auto gen1 = std::bind(random_levy_1d,alpha,1.);
	function<complex<double>()> gen;
	if(grid2)
		gen = [&gen1] () { return complex<double>(gen1(),gen1()); };
	else
		gen = [&gen1] () { return complex<double>(gen1(),0); };
	generate(sgr,gen,exponent);
	fill(sgr,grid1->unsafe_get_canvas(),(stripes_grid::proj_t)std::real,thickness,sharpness);
	if(grid2)
		fill(sgr,grid2->unsafe_get_canvas(),(stripes_grid::proj_t)std::imag,thickness,sharpness);
}
開發者ID:dgulotta,項目名稱:paintlines,代碼行數:14,代碼來源:paintsquiggles.cpp

示例8: sizeof

tap::CodeHeader::CodeHeader (address init, address size,
	const std::string & filename)
{
	//memset (block, 0, sizeof (block) );
	fill (block, block + sizeof (block), byte (0) );
	block [0]= 19; // Length of block: 17 bytes + flag  + checksum
	block [1]= 0;
	block [2]= 0;  // Flag: 00 -> header
	block [3]= 3;  // Type: code block.

	// File name.
	std::string::size_type l= filename.size ();
	if (l > 10)
		l= 10;
	for (std::string::size_type i= 0; i < 10; ++i)
		block [4 + i]= i < l ? filename [i] : ' ';

	// Length of the code block.
	block [14]= lobyte (size);
	block [15]= hibyte (size);

	// Start of the code block.
	block [16]= lobyte (init);
	block [17]= hibyte (init);

	// Parameter 2: 32768 in a code block.
	block [18]= 0x00;
	block [19]= 0x80;

	// Checksum
	byte check= block [2]; // Flag byte included.
	for (int i= 3; i < 20; ++i)
		check^= block [i];
	block [20]= check;
}
開發者ID:JamesGlanville,項目名稱:Z80,代碼行數:35,代碼來源:tap.cpp

示例9: repetition

//radius does not include center
Kernel::Kernel(int rep,int rad) : repetition(rep), radius(rad), height(2*radius +1) , width (2*radius+1)
{
  k_kernelArray = new float[height*width];
  //default is all 0
  fill(k_kernelArray, k_kernelArray+height*width, 0.f);
  factor = 0;
}
開發者ID:linzhong1992,項目名稱:cs3081,代碼行數:8,代碼來源:Kernel.cpp

示例10: main

int main (int argc, char **argv)
{
	// Setting Server's Listen Port
	ServerPort = SERVERPORT;
	cout << "Server listening on default port " << SERVERPORT << endl;

	// Server socket.
	ServerSocketFD = socket (AF_INET, SOCK_DGRAM, 0);

	// Server address initialization for binding.
	ServerAddress.sin_family = AF_INET;				// Socekt family.
	ServerAddress.sin_addr.s_addr = INADDR_ANY;		// Setting server IP. INADDR_ANY is the localhost IP.
	ServerAddress.sin_port = htons (ServerPort);	// Setting server port.
	fill ((char*)&(ServerAddress.sin_zero), (char*)&(ServerAddress.sin_zero)+8, '\0');

	// bind()
	bind (ServerSocketFD, (sockaddr *)&ServerAddress, sizeof (ServerAddress));

	// recvfrom() is blocking and will wait for any messages from client.
	socklen_t ClientAddressSize = sizeof (ClientAddress);
	NumOfBytesReceived = recvfrom (ServerSocketFD, Buffer, MAXBUFFERSIZE-1, 0, (sockaddr *)&ClientAddress, &ClientAddressSize);

	Buffer[NumOfBytesReceived] = '\0';
	cout << "Server got packet from " << inet_ntoa (ClientAddress.sin_addr) << " on socket " << ServerSocketFD << endl;
	cout << "Client says: " << Buffer << endl;

	// sendto()
	char ServerMessage[] = "Hello from Server. Now bye!";
	NumOfBytesSent = sendto (ServerSocketFD, ServerMessage, strlen (ServerMessage), 0, (sockaddr *)&ClientAddress, sizeof (ClientAddress));

	// Close connection.
	close (ServerSocketFD);
	return 0;
}
開發者ID:inf-eth,項目名稱:i02-0491-courses,代碼行數:34,代碼來源:Server.cpp

示例11: PrimeSieve

std::vector<bool>* PrimeSieve(const int64_t& LENGTH) {
    using std::ceil;
    using std::fill;
    using std::sqrt;
    using std::vector;
    // Fill with true
    vector<bool>* primes = new vector<bool>(LENGTH);
    fill(primes->begin(), primes->end(), true);

    // 0, 1 are not prime
    if (LENGTH >= 2) {
        primes->at(0) = primes->at(1) = false;
    } else if (LENGTH < 1) {
        return NULL;
    } else {
        primes->at(0) = false;
    }

    // Sieve
    for (int64_t i = 2; i < ceil(sqrt(LENGTH)); ++i) {
        if (primes->at(i)) {
            for (int64_t j = i * i; j < LENGTH; j += i) {
                primes->at(j) = false;
            }
        }
    }
    return primes;
}
開發者ID:agude,項目名稱:Project-Euler,代碼行數:28,代碼來源:alexlib.cpp

示例12: none

treatment::treatment(const real_t& Ma,
                     const pencil_grid& dgrid,
                     bspline& b,
                     inputs& inp,
                     outputs& out)
    : none(new constraint::disabled(b))
    , Ma(Ma)
    , rank_has_zero_zero_modes(dgrid.has_zero_zero_modes())
    , inp(inp)
    , out(out)
    , jacobiSvd(0, 0, Eigen::ComputeFullU | Eigen::ComputeFullV)
{
    using std::fill;
    fill(physical.begin(),  physical.end(),  none);
    fill(numerical.begin(), numerical.end(), none);
}
開發者ID:RhysU,項目名稱:suzerain,代碼行數:16,代碼來源:treatment_constraint.cpp

示例13: ApplicationType

INGR_TileHeader::INGR_TileHeader() :
    ApplicationType(0),
    SubTypeCode(0),
    WordsToFollow(0),
    PacketVersion(0),
    Identifier(0),
    Properties(0),
    DataTypeCode(0),
    TileSize(0),
    Reserved3(0)
{
    fill( Reserved, Reserved + CPL_ARRAYSIZE(Reserved), 0 );
    fill( Reserved2, Reserved2 + CPL_ARRAYSIZE(Reserved2), 0 );
    First.Start = 0;
    First.Allocated = 0;
    First.Used = 0;
}
開發者ID:garnertb,項目名稱:gdal,代碼行數:17,代碼來源:IntergraphBand.cpp

示例14: _invalidate_names

	static
	void _invalidate_names(Container& names)
	{
		using std::fill;
		using std::begin;
		using std::end;
		fill(begin(names), end(names), _traits::invalid_name());
	}
開發者ID:matus-chochlik,項目名稱:oglplu2,代碼行數:8,代碼來源:names.hpp

示例15: resize

void CoverageMap::resize ( int protLen )
{
    error = ( protLen == 0 );
    if ( !error ) {
        aaCovered.resize ( protLen );
        fill ( aaCovered.begin (), aaCovered.end (), false );
    }
}
開發者ID:proteinprospector,項目名稱:prospector,代碼行數:8,代碼來源:lu_coverage.cpp


注:本文中的std::fill方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。