home | help
std::experi...::copy_from(3)   C++ Standard Libary  std::experi...::copy_from(3)

NAME
     std::experimental::simd::copy_from - std::experimental::simd::copy_from

Synopsis
	template< class U, class Flags >	      (parallelism TS v2)
	void copy_from( const U* mem, Flags flags );

	The load function replaces all elements of a simd such that the i^th el-
     ement is
	assigned  with	static_cast<T>(mem[i])	for  all  i  in the range of [0,
     size()).

Parameters
	mem   - a pointer into an array where [mem, mem +  size())  is	a  valid
     range
	flags  -  if of type vector_aligned_tag, the load constructor may assume
     mem to point
		to storage aligned by memory_alignment_v<simd, U>

Type requirements
	-
	U must be a vectorizable type.
	-
	is_simd_flag_type_v<Flags> must be true.

Example
     // Run this code

      #include <cstddef>
      #include <experimental/simd>
      #include <iostream>
      #include <numeric>
      namespace stdx = std::experimental;

      void print(auto const& a)
      {
	  for (std::size_t i{}; i != std::size(a); ++i)
	      std::cout << a[i] << ' ';
	  std::cout << '\n';
      }

      int main()
      {
	  alignas(stdx::memory_alignment_v<stdx::native_simd<int>>)
	      std::array<int, stdx::native_simd<int>::size() * 2> mem = {};
	  std::iota(mem.begin(), mem.end(), 0);
	  print(mem);

	  stdx::native_simd<int> a; // uninitialized

	  a.copy_from(&mem[0], stdx::vector_aligned);
	  print(a);

	  a.copy_from(&mem[1], stdx::element_aligned); //  vector_aligned  would
     likely crash
	  print(a);
      }

Possible output:
      0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
      0 1 2 3 4 5 6 7
      1 2 3 4 5 6 7 8

See also
	memory_alignment    obtains an appropriate alignment for vector_aligned
	(parallelism TS v2) (class template)
	copy_to 	    stores simd elements to contiguous memory
	(parallelism TS v2) (public member function)
	constructor	    constructs a simd object
	(parallelism TS v2) (public member function)

http://cppreference.com 	   2024.06.10	    std::experi...::copy_from(3)

home | help