Search results
Top results related to what are some uses of a storage area network example worksheet
Top Answer
Answered May 23, 2017 · 247 votes
Return type forwarding in generic code
For non-generic code, like the initial example you gave, you can manually select to get a reference as a return type:
auto const& Example(int const& i) { return i; }
but in generic code you want to be able to perfectly forward a return type without knowing whether you are dealing with a reference or a value. decltype(auto) gives you that ability:
template<class Fun, class... Args>decltype(auto) Example(Fun fun, Args&&... args) { return fun(std::forward<Args>(args)...); }
Delaying return type deduction in recursive templates
In this Q&A a few days ago, an infinite recursion during template instantiation was encountered when the return type of the template was specified as decltype(iter(Int<i-1>{})) instead of decltype(auto).
template<int i> struct Int {};-constexpr auto iter(Int<0>) -> Int<0>;template<int i>constexpr auto iter(Int<i>) -> decltype(auto) { return iter(Int<i-1>{}); }int main() { decltype(iter(Int<10>{})) a; }
decltype(auto) is used here to delay the return type deduction after the dust of template instantiation has settled.
Other uses
You can also use decltype(auto) in other contexts, e.g. the draft Standard N3936 also states
7.1.6.4 auto specifier [dcl.spec.auto]
1 The auto and decltype(auto) type-specifiers designate a placeholder type that will be replaced later, either by deduction from an initializer or by explicit specification with a trailing-return-type. The auto type-specifier is also used to signify that a lambda is a generic lambda.
2 The placeholder type can appear with a function declarator in the decl-specifier-seq, type-specifier-seq, conversion-function-id, or trailing-return-type, in any context where such a declarator is valid. If the function declarator includes a trailing-return-type (8.3.5), that specifies the declared return type of the function. If the declared return type of the function contains a placeholder type, the return type of the function is deduced from return statements in the body of the function, if any.
The draft also contains this example of variable initialization:
int i;int&& f();auto x3a = i; // decltype(x3a) is intdecltype(auto) x3d = i; // decltype(x3d) is intauto x4a = (i); // decltype(x4a) is intdecltype(auto) x4d = (i); // decltype(x4d) is int&auto x5a = f(); // decltype(x5a) is intdecltype(auto) x5d = f(); // decltype(x5d) is int&&auto x6a = { 1, 2 }; // decltype(x6a) is std::initializer_list<int>decltype(auto) x6d = { 1, 2 }; // error, { 1, 2 } is not an expressionauto *x7a = &i; // decltype(x7a) is int*decltype(auto)*x7d = &i; // error, declared type is not plain decltype(auto)
1/5
Top Answer
Answered Oct 18, 2019 · 279 votes
I think you need to use template template syntax to pass a parameter whose type is a template dependent on another template like this:
template <template<class> class H, class S>void f(const H<S> &value) {}-
Here, H is a template, but I wanted this function to deal with all specializations of H.
NOTE: I've been programming c++ for many years and have only needed this once. I find that it is a rarely needed feature (of course handy when you need it!).
I've been trying to think of good examples, and to be honest, most of the time this isn't necessary, but let's contrive an example. Let's pretend that std::vector doesn't have a typedef value_type.
So how would you write a function which can create variables of the right type for the vectors elements? This would work.
template <template<class, class> class V, class T, class A>void f(V<T, A> &v) { // This can be "typename V<T, A>::value_type", // but we are pretending we don't have it T temp = v.back(); v.pop_back(); // Do some work on temp std::cout << temp << std::endl;}
NOTE: std::vector has two template parameters, type, and allocator, so we had to accept both of them. Fortunately, because of type deduction, we won't need to write out the exact type explicitly.
which you can use like this:
f<std::vector, int>(v); // v is of type std::vector<int> using any allocator-
or better yet, we can just use:
f(v); // everything is deduced, f can deal with a vector of any type!-
UPDATE: Even this contrived example, while illustrative, is no longer an amazing example due to c++11 introducing auto. Now the same function can be written as:
template <class Cont>void f(Cont &v) {- auto temp = v.back(); v.pop_back(); // Do some work on temp std::cout << temp << std::endl;}
which is how I'd prefer to write this type of code.
Other Answers
Answered Dec 17, 2015 · 200 votes
Actually, usecase for template template parameters is rather obvious. Once you learn that C++ stdlib has gaping hole of not defining stream output operators for standard container types, you would proceed to write something like:
template<typename T>static inline std::ostream& operator<<(std::ostream& out, std::list<T> const& v){ out << '['; if (!v.empty()) { for (typename std::list<T>::const_iterator i = v.begin(); ;) { out << *i; if (++i == v.end()) break; out << ", "; } } out << ']'; return out;}
Then you'd figure out that code for vector is just the same, for forward_list is the same, actually, even for multitude of map types it's still just the same. Those template classes don't have anything in common except for meta-interface/protocol, and using template template parameter allows to capture the commonality in all of them. Before proceeding to write a template though, it's worth to check a reference to recall that sequence containers accept 2 template arguments - for value type and allocator. While allocator is defaulted, we still should account for its existence in our template operator<<:
template<template <typename, typename> class Container, class V, class A>std::ostream& operator<<(std::ostream& out, Container<V, A> const& v)...-
Voila, that will work automagically for all present and future sequence containers adhering to the standard protocol. To add maps to the mix, it would take a peek at reference to note that they accept 4 template params, so we'd need another version of the operator<< above with 4-arg template template param. We'd also see that std:pair tries to be rendered with 2-arg operator<< for sequence types we defined previously, so we would provide a specialization just for std::pair.
Btw, with C+11 which allows variadic templates (and thus should allow variadic template template args), it would be possible to have single operator<< to rule them all. For example:
#include <iostream>#include <vector>#include <deque>#include <list>template<typename T, template<class,class...> class C, class... Args>std::ostream& operator <<(std::ostream& os, const C<T,Args...>& objs){ os << __PRETTY_FUNCTION__ << '\n'; for (auto const& obj : objs) os << obj << ' '; return os;}int main(){ std::vector<float> vf { 1.1, 2.2, 3.3, 4.4 }; std::cout << vf << '\n'; std::list<char> lc { 'a', 'b', 'c', 'd' }; std::cout << lc << '\n'; std::deque<int> di { 1, 2, 3, 4 }; std::cout << di << '\n'; return 0;}
Output
std::ostream &operator<<(std::ostream &, const C<T, Args...> &) [T = float, C = vector, Args = <std::__1::allocator<float>>]1.1 2.2 3.3 4.4 std::ostream &operator<<(std::ostream &, const C<T, Args...> &) [T = char, C = list, Args = <std::__1::allocator<char>>]a b c d std::ostream &operator<<(std::ostream &, const C<T, Args...> &) [T = int, C = deque, Args = <std::__1::allocator<int>>]1 2 3 4
Other Answers
Answered Oct 18, 2008 · 78 votes
Here is a simple example taken from 'Modern C++ Design - Generic Programming and Design Patterns Applied' by Andrei Alexandrescu:
He uses a classes with template template parameters in order to implement the policy pattern:
// Library codetemplate <template <class> class CreationPolicy>class WidgetManager : public CreationPolicy<Widget>{ ...};
He explains: Typically, the host class already knows, or can easily deduce, the template argument of the policy class. In the example above, WidgetManager always manages objects of type Widget, so requiring the user to specify Widget again in the instantiation of CreationPolicy is redundant and potentially dangerous.In this case, library code can use template template parameters for specifying policies.
The effect is that the client code can use 'WidgetManager' in a more elegant way:
typedef WidgetManager<MyCreationPolicy> MyWidgetMgr;-
Instead of the more cumbersome, and error prone way that a definition lacking template template arguments would have required:
typedef WidgetManager< MyCreationPolicy<Widget> > MyWidgetMgr;-
2/5
Top Answer
Answered Aug 25, 2013 · 1 votes
Exception handling is the ability of a program to intercept run-time errors, take corrective measures, and then continue.
One common use for exception handling could be found when you are attempting to open a file. If a file does not exist it could potentially make the program unreliable. In order to circumvent that issue you need to utilize an Exception handler. Here is a method that opens a text file that I made for an old project.
public static void openFile() { JFileChooser getData = new JFileChooser(); if ( getData.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { java.io.File dataSheet = getData.getSelectedFile(); try { input = new Scanner (dataSheet); } catch ( Exception e ) { GenerateInterface.theGame.printOutput( "File does not exist." ); } }}
As you can see if the file does not exist it catches (intercepts) the error, then it continues by running the code I wrote for that exception.
3/5
Top Answer
Answered Mar 17, 2014 · 7 votes
Probably one of the most interesting use cases I have seen would be Duff's Device the case where you extend a scope within a switch over multiple cases which would look something like this:
void send( int *to, const int *from, int count){ int n = (count + 7) / 8; switch(count % 8) { case 0: do { *to = *from++; // <- Scope start case 7: *to = *from++; case 6: *to = *from++; case 5: *to = *from++; case 4: *to = *from++; case 3: *to = *from++; case 2: *to = *from++; case 1: *to = *from++; } while(--n > 0); // <- Scope end }}
4/5
Top Answer
Answered Mar 13, 2009 · 29 votes
Perl facilitates the use of lists/hashes to implement named parameters, which I consider very elegant and a tremendous aid to self-documenting code.
my $result = $obj->method( flux_capacitance => 23, general_state => 'confusion', attitude_flags => ATTITUDE_PLEASANT | ATTITUDE_HELPFUL,);
Other Answers
Answered Dec 17, 2015 · 200 votes
Actually, usecase for template template parameters is rather obvious. Once you learn that C++ stdlib has gaping hole of not defining stream output operators for standard container types, you would proceed to write something like:
template<typename T>static inline std::ostream& operator<<(std::ostream& out, std::list<T> const& v){ out << '['; if (!v.empty()) { for (typename std::list<T>::const_iterator i = v.begin(); ;) { out << *i; if (++i == v.end()) break; out << ", "; } } out << ']'; return out;}
Then you'd figure out that code for vector is just the same, for forward_list is the same, actually, even for multitude of map types it's still just the same. Those template classes don't have anything in common except for meta-interface/protocol, and using template template parameter allows to capture the commonality in all of them. Before proceeding to write a template though, it's worth to check a reference to recall that sequence containers accept 2 template arguments - for value type and allocator. While allocator is defaulted, we still should account for its existence in our template operator<<:
template<template <typename, typename> class Container, class V, class A>std::ostream& operator<<(std::ostream& out, Container<V, A> const& v)...-
Voila, that will work automagically for all present and future sequence containers adhering to the standard protocol. To add maps to the mix, it would take a peek at reference to note that they accept 4 template params, so we'd need another version of the operator<< above with 4-arg template template param. We'd also see that std:pair tries to be rendered with 2-arg operator<< for sequence types we defined previously, so we would provide a specialization just for std::pair.
Btw, with C+11 which allows variadic templates (and thus should allow variadic template template args), it would be possible to have single operator<< to rule them all. For example:
#include <iostream>#include <vector>#include <deque>#include <list>template<typename T, template<class,class...> class C, class... Args>std::ostream& operator <<(std::ostream& os, const C<T,Args...>& objs){ os << __PRETTY_FUNCTION__ << '\n'; for (auto const& obj : objs) os << obj << ' '; return os;}int main(){ std::vector<float> vf { 1.1, 2.2, 3.3, 4.4 }; std::cout << vf << '\n'; std::list<char> lc { 'a', 'b', 'c', 'd' }; std::cout << lc << '\n'; std::deque<int> di { 1, 2, 3, 4 }; std::cout << di << '\n'; return 0;}
Output
std::ostream &operator<<(std::ostream &, const C<T, Args...> &) [T = float, C = vector, Args = <std::__1::allocator<float>>]1.1 2.2 3.3 4.4 std::ostream &operator<<(std::ostream &, const C<T, Args...> &) [T = char, C = list, Args = <std::__1::allocator<char>>]a b c d std::ostream &operator<<(std::ostream &, const C<T, Args...> &) [T = int, C = deque, Args = <std::__1::allocator<int>>]1 2 3 4
Other Answers
Answered Oct 18, 2008 · 78 votes
Here is a simple example taken from 'Modern C++ Design - Generic Programming and Design Patterns Applied' by Andrei Alexandrescu:
He uses a classes with template template parameters in order to implement the policy pattern:
// Library codetemplate <template <class> class CreationPolicy>class WidgetManager : public CreationPolicy<Widget>{ ...};
He explains: Typically, the host class already knows, or can easily deduce, the template argument of the policy class. In the example above, WidgetManager always manages objects of type Widget, so requiring the user to specify Widget again in the instantiation of CreationPolicy is redundant and potentially dangerous.In this case, library code can use template template parameters for specifying policies.
The effect is that the client code can use 'WidgetManager' in a more elegant way:
typedef WidgetManager<MyCreationPolicy> MyWidgetMgr;-
Instead of the more cumbersome, and error prone way that a definition lacking template template arguments would have required:
typedef WidgetManager< MyCreationPolicy<Widget> > MyWidgetMgr;-
5/5
www.geeksforgeeks.org › storage-area-networksStorage Area Networks - GeeksforGeeks
www.geeksforgeeks.org › storage-area-networksFeb 11, 2024 · A Storage Area Network (SAN) is a specialized network architecture that provides block-level storage access to servers and applications. SANs are typically used to provide high-speed, scalable storage for mission-critical applications, such as databases, email servers, and virtualized environments.
www.ibm.com › topics › storage-area-networkWhat Is a Storage Area Network (SAN)? | IBM
www.ibm.com › topics › storage-area-networkA storage area network (SAN) is a dedicated network that is tailored to a specific environment—combining servers, storage systems, networking switches, software and services. Why storage area networks are important.
www.techtarget.com › storage-area-network-SANWhat Is a Storage Area Network? SAN Explained - TechTarget
www.techtarget.com › storage-area-network-SANA storage area network (SAN) is a dedicated high-speed network or subnetwork that interconnects and presents shared pools of storage devices to multiple servers. The availability and accessibility of storage are critical concerns for enterprise computing.
- Stephen J. Bigelow
quizlet.com › 413724693 › 7-storage-area-network7 Storage Area Network Flashcards | Quizlet
quizlet.com › 413724693 › 7-storage-area-networka method of zoning that limits information about devices or depends on a device's own access restrictions to limit communication with other devices. Study with Quizlet and memorize flashcards containing terms like Network Attached Storage (NAS), NAS provides, NAS is specialized and more.
www.cisco.com › c › enWhat Is a Storage Area Network (SAN)? - Cisco
www.cisco.com › c › enA storage area network (SAN) is a dedicated high-speed network that makes storage devices accessible to servers by attaching storage directly to an operating system. It centralizes storage devices so they are easier to manage and communicate faster over media.
medium.com › @rmsrn › storage-area-networkStorage Area Network: Diagram, Components, Types, and Examples
medium.com › @rmsrn › storage-area-networkJul 22, 2022 · What are a storage area network examples? There are five examples, which are used as SAN protocol like as: Fibre Channel Protocol (FCP) Internet Small Computer System...
People also ask
What is a storage area network?
- Storage area networks are primarily used to connect servers to storage devices including disk-based storage and tape libraries. Fibre Channel (FC): A Fibre Channel is one of the maximum broadly used SAN storage connections.
Storage Area Networks - GeeksforGeeks
www.geeksforgeeks.org/storage-area-networks/What are the components of a storage area network?
- Let’s Start!! Storage area network has three major components like as servers, network infrastructure, and storage. But these components are classified further into following essential elements such as Node ports, Cabling, Interconnecting devices (such as FC switches or hubs), Storage arrays, and SAN management software.
Storage Area Network: Diagram, Components, Types, and Examples - M…
medium.com/@rmsrn.85/storage-area-network-diagram-components-types-and-examples-1398543fe31What is a storage area network protocol?
- A storage area network protocol is a type of connection that determines how devices and switches communicate with each other within a SAN fabric. A SAN can use one protocol or many. Certain devices are multiprotocol routers and devices. Multiprotocol routers and devices provide improved scalability, security and manageability.
What Is a Storage Area Network (SAN)? | IBM
www.ibm.com/topics/storage-area-networkWhat is a storage area network (SAN)?
- Storage Area Networks (SANs) transfer storage processing from servers to different networks. High availability, scalability, flexibility, and easier management are all made feasible by central and consolidated SANs. By using a remote copy, remote site data transfer and vaulting SANs shield data from malicious assaults and natural disasters.
Storage Area Networks - GeeksforGeeks
www.geeksforgeeks.org/storage-area-networks/What is storage architecture network?
- Storage architecture network also enable with SAN management applications, entire data storage, retrieval policy and consumption that allow governing the SAN’s resources. SAN protocol is a kind of connection that lets identify how devices and switches are making communication with each other along with storage area network fabric.
Storage Area Network: Diagram, Components, Types, and Examples - M…
medium.com/@rmsrn.85/storage-area-network-diagram-components-types-and-examples-1398543fe31What protocols are used by storage area networks (SAN)?
- There are multiple protocols used by Storage Area Networks (SAN), Below are some mentioned protocols supported by the Storage Area Network: Fibre Channel Protocol (FCP): It is the Storage Area Network protocol that is most frequently utilised. It is a Fibre Channel (FC) network mapping of a SCSI command.
Storage Area Networks - GeeksforGeeks
www.geeksforgeeks.org/storage-area-networks/quizlet.com › 831441911 › storage-area-networks-andStorage Area Networks and Cloud Flashcards | Quizlet
quizlet.com › 831441911 › storage-area-networks-andStudy with Quizlet and memorize flashcards containing terms like SAN (storage area network), Fibre Channel (FC), Fibre Channel over Ethernet (FCoE) and more.
Searches related to what are some uses of a storage area network example worksheet