// @HEADER // ***************************************************************************** // Tpetra: Templated Linear Algebra Services Package // // Copyright 2008 NTESS and the Tpetra contributors. // SPDX-License-Identifier: BSD-3-Clause // ***************************************************************************** // @HEADER #ifndef __Teuchos_MatrixMarket_assignScalar_hpp #define __Teuchos_MatrixMarket_assignScalar_hpp #include #include #include namespace Teuchos { namespace MatrixMarket { namespace details { /// \class ScalarAssigner /// \brief Implementation detail of assignScalar(). /// /// We define a class because template functions can't (in the /// current C++ standard) have default template parameters. template::isComplex> class ScalarAssigner { public: static void assign (Scalar& val, const typename Teuchos::ScalarTraits::magnitudeType& real, const typename Teuchos::ScalarTraits::magnitudeType& imag); }; // Partial specialization for real Scalar types. template class ScalarAssigner { public: static void assign (RealType& val, const typename Teuchos::ScalarTraits::magnitudeType& real, const typename Teuchos::ScalarTraits::magnitudeType& imag) { // imag had better be zero. We're ignoring it regardless. (void) imag; val = real; } }; #ifdef HAVE_TEUCHOS_COMPLEX // Partial specialization for complex Scalar types. // MagType is the template parameter for std::complex. template class ScalarAssigner, true> { public: static void assign (std::complex& val, const typename Teuchos::ScalarTraits >::magnitudeType& real, const typename Teuchos::ScalarTraits >::magnitudeType& imag) { val = std::complex (real, imag); } }; #endif // HAVE_TEUCHOS_COMPLEX /// \fn assignScalar /// \brief Assign to a Scalar value: val = S(real, imag). /// /// We have to template it because we don't know that S is a /// complex type; if we write S(real,imag), the compiler will /// complain if S is a real type. template void assignScalar (Scalar& val, const typename Teuchos::ScalarTraits::magnitudeType& real, const typename Teuchos::ScalarTraits::magnitudeType& imag) { ScalarAssigner::assign (val, real, imag); } } // namespace details } // namespace MatrixMarket } // namespace Teuchos #endif // __Teuchos_MatrixMarket_assignScalar_hpp